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

当前回答

一个建议的解决方案在这里没有工作,我发现文件实际上是一个链接到一些特殊字符:

% ls -l StoreLogo.png
lrwxrwxrwx 1 janus janus 8 Feb 21 10:37 StoreLogo.png -> ''$'\211''PNG'$'\r\n\032\n'

% git status    
Changes not staged for commit:
    modified:   StoreLogo.png

% git rm --cached -r StoreLogo.png
rm 'src/GWallet.Frontend.XF.UWP/Assets/StoreLogo.png'

% git reset StoreLogo.png         
Unstaged changes after reset:
M   src/GWallet.Frontend.XF.UWP/Assets/StoreLogo.png

% git status                      
Changes not staged for commit:
    modified:   StoreLogo.png

其他回答

这快把我逼疯了,尤其是没有网上找到的任何解决方案,我都无法解决这个问题。下面是我的解决方法。因为这是一个同事的作品,所以不能在这里获得学分:)

问题的来源:我最初安装的git在windows上没有自动行转换。这导致我最初提交到GLFW没有适当的行结束。

注意:这只是一个本地解决方案。下一个克隆回购的人 仍然会被这个问题困住。一个永久的解决办法是 在这里找到: https://help.github.com/articles/dealing-with-line-endings/ re-normalizing-a-repository。

设置: Xubuntu 12.04 Git回购与glfw项目

问题:无法重置glfw文件。不管我怎么尝试,它们总是显示为修改过的。

解决:

edit .gitattributes

Comment out the line:    # text=auto

Save the file

restore .gitattributes:   git checkout .gitattributes

有多种问题会导致这种行为:

行结束归一化

我也遇到过这种问题。归根结底是git自动将crlf转换为lf。这通常是由单个文件中混合的行结束符引起的。该文件在索引中得到了规范化,但是当git再次对其进行反规范化以与工作树中的文件进行区分时,结果是不同的。

但如果你想解决这个问题,你应该禁用core。将所有行结束改为lf,然后再次启用它。或者你可以通过以下方法完全禁用它:

git config --global core.autocrlf false

而不是核心。独裁,你也可以考虑使用.gitattributes文件。通过这种方式,您可以确保使用repo的每个人都使用相同的规范化规则,防止混合的行尾进入存储库。

还要考虑设置核心。如果您希望git在执行不可逆规范化时发出警告,则使用Safecrlf。

git的手册上写着:

CRLF转换有轻微的可能性 破坏数据。autocrlf = true将 在提交和期间将CRLF转换为LF 结帐时LF到CRLF。一个文件 它含有LF和CRLF的混合物 之前无法重新创建提交 git。对于文本文件,这是 正确的做法是:修正直线 这样我们就只有LF线 存储库中的结尾。但对于 二进制文件 分类为文本的转换可以 腐败的数据。

不区分大小写的文件系统

在不区分大小写的文件系统中,当存储库中有不同大小写的相同文件名时,git尝试签出两个文件名,但最终只有一个出现在文件系统中。当git尝试比较第二个文件时,它会将其与错误的文件进行比较。

解决方案要么是切换到一个不区分大小写的文件系统,但这在大多数情况下是不可行的,要么是将一个文件重命名并提交到另一个文件系统上。

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

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

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

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

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

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

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

对我来说,问题是在执行命令时打开了Visual Studio

Git签出<文件>

关闭Visual Studio后,命令生效了,我终于可以从堆栈中应用我的工作了。因此,检查所有可能更改代码的应用程序,例如SourceTree, SmartGit, NotePad, notepad++和其他编辑器。

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