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

当前回答

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

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

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

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

其他回答

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

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

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

git add -A
git reset --hard

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

git checkout mainbranch --force

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

我是这样解决的:

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


这对我来说很有效。

我通过编辑.git / config解决了这个问题,添加了:

[branch "name_branch"]
    remote = origin
    merge = refs/heads/name_branch

然后我进入。git / refs / heads / name_branch 并将最后一个committer代码的id放在这里