git状态显示修改,git checkout - < file>不会删除它们 [英] git status shows modifications, git checkout -- <file> doesn't remove them

查看:147
本文介绍了git状态显示修改,git checkout - < file>不会删除它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想删除对我工作副本的所有更改。

运行 git status 显示已修改的文件。 b我没有做任何事情似乎可以消除这些修改。

例如:


  rbellamy @ PROMETHEUS / d / Development / rhino-etl(master)
$ git status
#分支大师
#已更改但未更新:
#(使用git add< file> ; ...更新将提交的内容)
#(使用git checkout - < file> ...放弃工作目录中的更改)

#修改:Rhino.Etl.Core / Enumerables / CachingEnumerable.cs
#修改:Rhino.Etl.Core / Pipelines / SingleThreadedPipelineExecuter.cs
#修改:Rhino.Etl.Tests / Rhino.Etl.Tests.csproj
#modified:Rhino.Etl.Tests / SingleThreadedPipelineExecuterTest.cs

没有更改添加到提交中(使用git add和/或git commit -a)

rbellamy @ PROMETHEUS / d / Development / rhino-etl(master)
$ git checkout - Rh ino.Etl.Core / Enumerables / CachingEnumerable.cs

rbellamy @ PROMETHEUS / d / Development / rhino-etl(master)
$ git status
#在分支master
#已更改但未更新:
#(使用git add< file> ...更新将提交的内容)
#(使用git checkout - < file> ;. ..以放弃工作目录中的更改)

#修改:Rhino.Etl.Core / Enumerables / CachingEnumerable.cs
#修改:Rhino.Etl.Core / Pipelines / SingleThreadedPipelineExecuter。 cs
#修改:Rhino.Etl.Tests / Rhino.Etl.Tests.csproj
#修改:Rhino.Etl.Tests / SingleThreadedPipelineExecuterTest.cs

没有更改添加到commit(使用git add和/或git commit -a)

rbellamy @ PROMETHEUS / d / Development / rhino-etl(master)
$ git checkout`git ls-文件-m`

rbellamy @ PROMETHEUS / d / Development / rhino-etl(master)
$ git status
#在分支主机上
#已更改但未更新:
#(使用git add&l t; file> ...来更新将提交的内容)
#(使用git checkout - < file> ...放弃工作目录中的更改)

#修改:Rhino.Etl.Core / Enumerables / CachingEnumerable.cs
#修改:Rhino.Etl.Core / Pipelines / SingleThreadedPipelineExecuter.cs
#修改:Rhino.Etl.Tests / Rhino.Etl。 Tests.csproj
#modified:Rhino.Etl.Tests / SingleThreadedPipelineExecuterTest.cs

没有更改添加到提交(使用git add和/或git commit -a)

rbellamy @ PROMETHEUS / d / Development / rhino-etl(master)
$ git reset --hard HEAD
HEAD现在在6c857e7 boo库更新到2.0.9.2和犀牛.dsl.dll更新。

rbellamy @ PROMETHEUS / d / Development / rhino-etl(master)
$ git status
#分支主
#已更改但未更新:
#(使用git add< file> ...更新将要提交的内容)
#(使用git checkout - < file> ...放弃工作目录中的更改)

#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

没有更改添加到提交中(使用git add和/或 git commit -a)


解决方案

可能会导致此行为:

结束标准化

种类问题也是如此。它归结为自动将crlf转换为lf的git。这通常是由单个文件中的混合行尾引起的。该文件在索引中得到了规范化,但是当git再次非规范化它以对照工作树中的文件时,结果会有所不同。



但是如果你想要解决这个问题,您应该禁用 core.autocrlf ,将所有行结束符更改为lf,然后再次启用它。或者你可以通过这样做来完全禁用它:

  git config --global core.autocrlf false 

除了 core.autocrlf 外,您还可以考虑使用 .gitattribute 文件。这样,您可以确保使用repo的每个人都使用相同的规范化规则,从而防止混合行结束进入存储库。



另请考虑设置 core.safecrlf 警告您是否希望git在执行不可逆规范化时提醒您。



git manpages 会这样说:


CRLF转换支持轻微机会
的腐败数据。 autocrlf = true将
在提交期间将CRLF转换为LF,并在结帐期间将
LF转换为CRLF。在提交之前包含LF和CRLF
混合的文件
不能通过git重新创建
。对于文本文件来说,这是
正确的做法:它纠正行
的结局,使得我们在存储库中只有LF行
结尾。但是,对于
二进制文件,偶然
归类为文本,转换可能
损坏的数据。


不区分大小写的文件系统



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



解决方案将切换到非大小写不敏感的文件系统,但是这个大多数情况下不可行,或者重命名并提交另一个文件系统上的文件之一。


I would like to remove all changes to my working copy.
Running git status shows files modified.
Nothing I do seems to remove these modifications.
E.g.:

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")

解决方案

There are multiple problems the can cause this behaviour:

Line ending normalization

I've had these kinds of problems too. It comes down to git automatically converting crlf to lf. This is typically caused by mixed line endings in a single file. The file gets normalized in the index, but when git then denormalizes it again to diff it against the file in the working tree, the result is different.

But if you want to fix this, you should disable core.autocrlf, change all line endings to lf, and then enable it again. Or you can disable it altogether by doing:

git config --global core.autocrlf false

Instead of core.autocrlf, you can also consider using .gitattribute files. This way, you can make sure everyone using the repo uses the same normalization rules, preventing mixed line endings getting into the repository.

Also consider setting core.safecrlf to warn if you want git to warn you when a non-reversible normalization would be performed.

The git manpages say this:

CRLF conversion bears a slight chance of corrupting data. autocrlf=true will convert CRLF to LF during commit and LF to CRLF during checkout. A file that contains a mixture of LF and CRLF before the commit cannot be recreated by git. For text files this is the right thing to do: it corrects line endings such that we have only LF line endings in the repository. But for binary files that are accidentally classified as text the conversion can corrupt data.

Case-insensitive file systems

On case-insensitive filesystems, when the same filename with different casing is in the repository, git tries to checkout both, but only one ends up on the file system. When git tries to compare the second one, it would compare it to the wrong file.

The solution would either be switching to a non-case insensitive filesystem, but this in most cases is not feasible or renaming and committing one of the files on another filesystem.

这篇关于git状态显示修改,git checkout - &lt; file&gt;不会删除它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆