我之前已经能够通过 SourceTree 通过执行“Discard”函数来撤消更改,该函数在幕后会生成以下命令:
git -c diff.mnemonicprefix=false -c core.quotepath=false reset -q HEAD -- myproj.csproj
git -c diff.mnemonicprefix=false -c core.quotepath=false checkout HEAD -- myproj.csproj
突然间这不起作用了。我执行“放弃”,没有发生错误,重新刷新视图,但文件仍然“已修改”。然后我尝试在命令行中执行相同的操作,得到以下相同的结果:
c:\myproject> git reset HEAD
Unstaged changes after reset:
M myproj.csproj
为什么它仍然被列为未暂存的更改?
我已经验证该文件确实可写(没有进程持有锁)
update
git checkout
也没有用:
C:\myproject>git checkout myproj.csproj
C:\myproject>git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: myproj.csproj
#
no changes added to commit (use "git add" and/or "git commit -a")
Update 2还尝试过:
git checkout --
git checkout -- .
git checkout HEAD
,这些都不能解决我的问题
更新 3 - 又近了一大步:
结果当我结帐时,.csproj 确实恢复到正确的版本,but签出的版本使用不同的换行编码。签入版本有 CR-LF (0D-0A) 用于换行,而签出版本只有 LF (0A)。因此 git 相信文件的每一行都是不同的。为什么这个?
更新4:添加了 SourceTree 发出的第二行 git-commands。我第一次没有注意到,所以我想git reset HEAD
会做任何事。这并没有改变根本问题仍然与 CR/LF 相关的事实(我认为)
summary我从未找到该问题的解决方案,但我通过签入文件“解决”了它。我原来的问题不包含 SourceTree 确实发出了正确的命令来回滚我想要的信息,因此这里的大多数答案都解决了这个问题。这real问题仍然不清楚,但我的主要理论是它与 CR/LF 相关。
如果您需要删除本地更改,请运行以下命令
git checkout -- file_name
git reset HEAD
不删除本地更改。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)