问题描述
以前我可以通过执行Discard函数来撤销SourceTree中的更改,该函数在内部生成此命令:
git -c diff.mnemonicprefix = false -c core.quotepath = false重置-q HEAD - myproj.csproj
git -c diff.mnemonicprefix = false -c core.quotepath = false checkout HEAD - - myproj.csproj
突然这不起作用。我做丢弃,没有错误发生,refreesh视图,但文件仍然修改。然后我试着在命令行中做同样的事情,结果如下:
c:\ myproject> git reset HEAD
重置后的非暂存变更:
M myproj.csproj
为什么它仍被列为未分离的变更?
我已验证文件确实可写入(没有进程持有一个锁)
更新
$ b git checkout
也不起作用:
C:\ myproject> git checkout myproj.csproj
C:\ myproject> git status
#在分支主机上
#没有为commit提交更改:
#(使用git add< file> ...更新将提交的内容)
#(使用git checkout - < file> ...放弃工作目录中的更改)
#
#modified:myproj.csproj
#
没有更改添加到提交中(使用git add和/或git commit -a)
更新2
也尝试过:
git checkout -
git checkout - 。
git checkout HEAD
,其中没有一个解决了我的问题
更新3 - 巨大的步骤更接近:
结果是,当我执行结账时,.csproj确实恢复为正确的版本,但 out版本使用不同的换行符编码。虽然签入版本具有用于换行的CR-LF(0D-0A),但检出仅具有LF(0A)。因此git相信文件在每一行上都是不同的。为什么这么做?
update 4:添加了由SourceTree发布的第二行git-commands。我没有注意到第一次,这就是为什么我认为 git reset HEAD
会做任何事。这并没有改变这个事实,即潜在的问题仍然是与CR / LF相关的(我认为)
摘要
I从来没有找到解决这个问题的办法,但我通过签入文件解决了它。我原来的问题并没有包含SourceTree确实发布了正确的命令来回滚我想要的信息,所以这里的大部分答案都解决了这个问题。真正的问题仍然不清楚,但我的主要理论是CR / LF相关。
如果您需要删除本地更改,请运行以下命令:
git checkout - file_name
git reset HEAD
不会删除本地更改。
I've previously been able to undo changes through SourceTree by performing the "Discard" function, which under the hood produces this command:
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
Suddenly this doesn't work. I do the Discard, no error occurs, refreesh the view, but the files are still "modified". I've then tried to do the same in the command line with the following, same result:
c:\myproject> git reset HEAD
Unstaged changes after reset:
M myproj.csproj
Why is it still listed as an unstaged change?
I've verified that the file is indeed writable (no process is holding a lock)
update
git checkout
didn't work either:
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 2Also tried:
git checkout --
git checkout -- .
git checkout HEAD
,none of which solves my problem
update 3 - huge step closer:
Turns out when I do the checkout, the .csproj is indeed reverted to the correct version, but the checked out version uses a different line feed encoding. While the checked-in version has CR-LF (0D-0A) for line feed, the checked-out has only LF (0A). Hence git belives the file to be different on every single line. Why this?
update 4: added the second line of git-commands issued by SourceTree. I didn't notice that the first time around, that's why I thought git reset HEAD
would do anything. This doesn't change the fact that the underlying problem still is CR/LF-related (I think)
summaryI never found a solution to the issue, but I "solved" it by checking in the file. My original question didn't contain information that SourceTree indeed issued the correct commands to rollback what I wanted, so most answers here address that issue. The real issue is still unclear, but my main theory is that it was CR/LF related.
If you need to remove local changes then run following command
git checkout -- file_name
git reset HEAD
does not remove local changes.
这篇关于为什么不会“git reset HEAD”撤消我未提交的未分离更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!