我想删除对我的工作副本的所有更改。 运行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 commit -m "随机提交"

git重置-硬头~1

其他回答

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

git stash save --keep-index

然后删除存储:

git stash drop

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

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

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

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

同样的问题出现了两次!这两次都是我做了一些更改,然后试图把它们放回去。不能弹出的变化,因为我有很多文件被改变-但他们不是!它们完全一样。

我现在认为我已经尝试了以上所有的解决方案,但都没有成功。在尝试了

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

我现在几乎修改了存储库中的所有文件。

当对文件进行差分时,它会说我已经删除了所有行,然后重新添加它们。

有点令人不安。从今以后,我再也不偷东西了。

唯一的解决方案是克隆一个新的存储库并重新开始。(上次做的)

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

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

当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