我想删除对我的工作副本的所有更改。 运行git状态显示已修改的文件。 我所做的一切似乎都无法消除这些修改。 例如:

rbellamy@PROMETHEUS /d/Development/rhino-etl (master)
$ git status
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   Rhino.Etl.Core/Enumerables/CachingEnumerable.cs
#       modified:   Rhino.Etl.Core/Pipelines/SingleThreadedPipelineExecuter.cs
#       modified:   Rhino.Etl.Tests/Rhino.Etl.Tests.csproj
#       modified:   Rhino.Etl.Tests/SingleThreadedPipelineExecuterTest.cs
#
no changes added to commit (use "git add" and/or "git commit -a")

rbellamy@PROMETHEUS /d/Development/rhino-etl (master)
$ git checkout -- Rhino.Etl.Core/Enumerables/CachingEnumerable.cs

rbellamy@PROMETHEUS /d/Development/rhino-etl (master)
$ git status
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   Rhino.Etl.Core/Enumerables/CachingEnumerable.cs
#       modified:   Rhino.Etl.Core/Pipelines/SingleThreadedPipelineExecuter.cs
#       modified:   Rhino.Etl.Tests/Rhino.Etl.Tests.csproj
#       modified:   Rhino.Etl.Tests/SingleThreadedPipelineExecuterTest.cs
#
no changes added to commit (use "git add" and/or "git commit -a")

rbellamy@PROMETHEUS /d/Development/rhino-etl (master)
$ git checkout `git ls-files -m`

rbellamy@PROMETHEUS /d/Development/rhino-etl (master)
$ git status
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   Rhino.Etl.Core/Enumerables/CachingEnumerable.cs
#       modified:   Rhino.Etl.Core/Pipelines/SingleThreadedPipelineExecuter.cs
#       modified:   Rhino.Etl.Tests/Rhino.Etl.Tests.csproj
#       modified:   Rhino.Etl.Tests/SingleThreadedPipelineExecuterTest.cs
#
no changes added to commit (use "git add" and/or "git commit -a")

rbellamy@PROMETHEUS /d/Development/rhino-etl (master)
$ git reset --hard HEAD
HEAD is now at 6c857e7 boo libraries updated to 2.0.9.2 and rhino.dsl.dll updated.

rbellamy@PROMETHEUS /d/Development/rhino-etl (master)
$ git status
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   Rhino.Etl.Core/Enumerables/CachingEnumerable.cs
#       modified:   Rhino.Etl.Core/Pipelines/SingleThreadedPipelineExecuter.cs
#       modified:   Rhino.Etl.Tests/Rhino.Etl.Tests.csproj
#       modified:   Rhino.Etl.Tests/SingleThreadedPipelineExecuterTest.cs
#
no changes added to commit (use "git add" and/or "git commit -a")

当前回答

这一页上的其他内容都不起作用。这最终对我有用。没有显示未跟踪或已提交的文件。

git add -A
git reset --hard

其他回答

一个建议的解决方案在这里没有工作,我发现文件实际上是一个链接到一些特殊字符:

% ls -l StoreLogo.png
lrwxrwxrwx 1 janus janus 8 Feb 21 10:37 StoreLogo.png -> ''$'\211''PNG'$'\r\n\032\n'

% git status    
Changes not staged for commit:
    modified:   StoreLogo.png

% git rm --cached -r StoreLogo.png
rm 'src/GWallet.Frontend.XF.UWP/Assets/StoreLogo.png'

% git reset StoreLogo.png         
Unstaged changes after reset:
M   src/GWallet.Frontend.XF.UWP/Assets/StoreLogo.png

% git status                      
Changes not staged for commit:
    modified:   StoreLogo.png

对于将来遇到此问题的人:文件模式更改也可能有相同的症状。Git配置核心。Filemode false将修复它。

试着做一个

Git checkout -f

这将清除当前工作的本地回购中的所有更改

当repo的贡献者在Linux机器上工作时,或者具有Cygwin和文件权限的窗口被更改时,也会发生此问题。Git只知道755和644。

这个问题的例子以及如何检查它:

git diff styleguide/filename

diff --git a/filename b/filename
old mode 100644
new mode 100755

为了避免这种情况,你应该确保你正确设置git使用

git config --global core.filemode false

这里有很多解决方案,也许我应该在提出自己的解决方案之前尝试其中一些。总之,这里还有一个…

我们的问题是,我们没有对结束行进行强制执行,并且存储库混合使用DOS / Unix。更糟糕的是,在这个位置上,它实际上是一个开源的回购,而我们已经分叉了。那些拥有操作系统存储库主要所有权的人决定将所有的结束行更改为Unix,并且提交包含一个.gitattributes来强制行结束。

不幸的是,这似乎会导致像这里描述的那样的问题,一旦合并DOS-2-Unix之前的代码,文件将永远被标记为已更改,无法恢复。

在我的研究过程中,我遇到了- https://help.github.com/articles/dealing-with-line-endings/ -如果我再次面临这个问题,我会首先尝试一下。


以下是我所做的:

I'd initially done a merge before realising I had this problem and had to abort that - git reset --hard HEAD (I ran into a merge conflict. How can I abort the merge?) I opened the files in question in VIM and changed to Unix (:set ff=unix). A tool like dos2unix could be used instead of course committed merged the master in (the master has the DOS-2-Unix changes) git checkout old-code-branch; git merge master Resolved conflicts and the files were DOS again so had to :set ff=unix when in VIM. (Note I have installed https://github.com/itchyny/lightline.vim which allowed me to see what the file format is on the VIM statusline) committed. All sorted!