我想删除对我的工作副本的所有更改。 运行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中有两个文件,它们的名称只在符号寄存器中有所不同。unix系统认为它们是两个不同的文件,但Windows系统却疯了。为了解决这个问题,我们删除了服务器上的一个文件。在那之后,在Windows上的本地存储库中帮助了接下来的几个命令(以不同的顺序):

git reset --hard
git pull origin
git merge

其他回答

我有一个老的冗余分支,有不同的行尾。切换到这个让我有点卡住了,直到我用了一些力。

git checkout mainbranch --force

接着是一个快速的git分支-D brokenbranch。

当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 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。

我有一个.bat文件有同样的问题(无法摆脱它,它在未跟踪的文件)。Git签出—不起作用,本页上的任何建议也不起作用。唯一对我有用的是:

git stash save --keep-index

然后删除存储:

git stash drop

我在Windows上遇到了这个问题,但还没有准备好研究使用配置全局核心的后果。我也不准备放弃我的其他私人分支和好东西,开始一个新的克隆。我只是需要做点事。现在。

这对我来说是可行的,因为你让git完全重写你的工作目录:

git rm --cached -r .
git reset --hard

(请注意,仅仅运行git reset -hard不够好,在重置之前对文件进行简单的rm也不够好,就像对原始问题的评论中建议的那样)