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

当前回答

当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

其他回答

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

git add -A
git reset --hard

我是这样解决的:

复制所需的正确代码的内容 从磁盘上删除导致问题的文件(您无法还原的文件)。现在,您应该会发现同一文件的两个版本都被标记为已删除。 提交文件的删除。 再次使用相同的名称创建文件,并粘贴在步骤1中复制的正确代码中 提交新文件的创建。


这对我来说很有效。

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

我没能:

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。

有一致的行尾是件好事。例如,它不会触发不必要的合并,尽管这是微不足道的。我曾经见过Visual Studio用混合行结尾创建文件。

还有一些程序,如bash(在linux上)确实要求.sh文件以LF终止。

为了确保发生这种情况,可以使用gitattributes。不管autcrlf的值是什么,它都在存储库级别上工作。

例如,你可以有这样的.gitattributes: *文本=汽车

如果对您的情况有影响,您还可以更具体地指定每个文件类型/扩展名。

然后,selff可以在本地转换Windows程序的行结束符。

在c# / c++ /Java/Ruby/R, Windows/Linux的混合项目中,这种方法运行良好。目前还没有问题。

我遇到的问题是,windows不关心文件名大写,但git关心。因此git存储了文件的小写和大写版本,但只能签出其中一个。