我想删除对我的工作副本的所有更改。 运行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")

当前回答

另一个可能对人们有用的解决方案,因为没有一个文本选项对我有用:

将.gitattributes的内容替换为一行:* binary。这告诉git将每个文件视为二进制文件,它不能对其做任何事情。 检查该消息的违规文件已经消失;如果不是,您可以git checkout——<files>将它们恢复到存储库版本 Git签出——.gitattributes将.gitattributes文件恢复到初始状态 检查文件是否仍然没有标记为已更改。

其他回答

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

我们的问题是,我们没有对结束行进行强制执行,并且存储库混合使用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!

我也有同样的症状,但是由不同的原因引起的。

我没能:

git checkout app.js //did nothing
git rm app.js //did nothing
rm -rf app.js //did nothing

即使在 git rm——缓存app.js,它的签名为删除,在未跟踪的文件中,我可以看到app.js。但是当我尝试rm -rf app.js并再次执行git状态时,它仍然显示我的文件处于“untracked”状态。

经过同事的几次尝试,我们发现,这是由Grunt引起的!

由于Grunt已经打开,并且因为app.js已经从其他几个js文件中生成,我们发现在每次使用js文件(也是这个app.js)的操作之后,Grunt再次重新创建app.js。

我们公司也遇到过类似的情况。所提出的方法没有一个对我们没有帮助。作为研究的结果,问题被揭示了。问题是在Git中有两个文件,它们的名称只在符号寄存器中有所不同。unix系统认为它们是两个不同的文件,但Windows系统却疯了。为了解决这个问题,我们删除了服务器上的一个文件。在那之后,在Windows上的本地存储库中帮助了接下来的几个命令(以不同的顺序):

git reset --hard
git pull origin
git merge

我只能通过临时删除我的repo的.gitattributes文件来修复这个问题(其中定义了* text=auto和*.c text)。

删除后我运行git状态,修改消失了。即使在.gitattributes被放回原处之后,它们也没有返回。

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