即使内容相同,Git状态也会将文件显示为已更改

我收到了其他人的git checkout,并试图将未分离的更改提交到本地存储库。 但是,即使内容完全相同, 很多 (如果不是每个)文件都显示为已修改

我已经将core.fileMode设置为false,并将core.autocrlf设置为false,但未成功。

值得一提的是,我收到的Git回购是来自使用Windows的人,而我使用的是Linux。

我能做些什么来实现实际的变化?

编辑:输出的git config -l

 user.name=Aron Rotteveel user.email=<removed> color.diff=auto color.status=auto color.branch=auto color.interactive=auto color.ui=true color.pager=true color.branch.current=yellow reverse color.branch.local=yellow color.branch.remote=green color.diff.meta=yellow bold color.diff.frag=magenta bold color.diff.old=red bold color.diff.new=green bold color.status.added=yellow color.status.changed=green color.status.untracked=cyan core.pager=less -FRSX core.whitespace=fix,-indent-with-non-tab,trailing-space,cr-at-eol alias.co=checkout core.repositoryformatversion=0 core.filemode=false core.bare=false core.logallrefupdates=true core.symlinks=false core.ignorecase=true core.hidedotfiles=dotGitOnly core.autocrlf=false remote.origin.url=<removed> remote.origin.fetch=+refs/heads/*:refs/remotes/origin/* 

更新:添加一些随机的示例文件。 这些文件只是明文,所以最容易包含。

原始文件位于: https : //gist.github.com/c3c5302430935155ef3d 。 Hexdumps肯定地表明这些文件是不同的,但我不知道是什么原因造成的,以及如何解决这个问题。

HEAD版本:

 0000000: 4854 4d4c 2e53 6166 654f 626a 6563 740d HTML.SafeObject. 0000010: 0a54 5950 453a 2062 6f6f 6c0d 0a56 4552 .TYPE: bool..VER 0000020: 5349 4f4e 3a20 332e 312e 310d 0a44 4546 SION: 3.1.1..DEF 0000030: 4155 4c54 3a20 6661 6c73 650d 0a2d 2d44 AULT: false..--D 0000040: 4553 4352 4950 5449 4f4e 2d2d 0d0a 3c70 ESCRIPTION--..<p 0000050: 3e0d 0a20 2020 2057 6865 7468 6572 206f >.. Whether o 0000060: 7220 6e6f 7420 746f 2070 6572 6d69 7420 r not to permit 0000070: 6f62 6a65 6374 2074 6167 7320 696e 2064 object tags in d 0000080: 6f63 756d 656e 7473 2c20 7769 7468 2061 ocuments, with a 0000090: 206e 756d 6265 7220 6f66 2065 7874 7261 number of extra 00000a0: 0d0a 2020 2020 7365 6375 7269 7479 2066 .. security f 00000b0: 6561 7475 7265 7320 6164 6465 6420 746f eatures added to 00000c0: 2070 7265 7665 6e74 2073 6372 6970 7420 prevent script 00000d0: 6578 6563 7574 696f 6e2e 2054 6869 7320 execution. This 00000e0: 6973 2073 696d 696c 6172 2074 6f0d 0a20 is similar to.. 00000f0: 2020 2077 6861 7420 7765 6273 6974 6573 what websites 0000100: 206c 696b 6520 4d79 5370 6163 6520 646f like MySpace do 0000110: 2074 6f20 6f62 6a65 6374 2074 6167 732e to object tags. 0000120: 2020 596f 7520 7368 6f75 6c64 2061 6c73 You should als 0000130: 6f20 656e 6162 6c65 0d0a 2020 2020 254f o enable.. %O 0000140: 7574 7075 742e 466c 6173 6843 6f6d 7061 utput.FlashCompa 0000150: 7420 696e 206f 7264 6572 2074 6f20 6765 t in order to ge 0000160: 6e65 7261 7465 2049 6e74 6572 6e65 7420 nerate Internet 0000170: 4578 706c 6f72 6572 0d0a 2020 2020 636f Explorer.. co 0000180: 6d70 6174 6962 696c 6974 7920 636f 6465 mpatibility code 0000190: 2066 6f72 2079 6f75 7220 6f62 6a65 6374 for your object 00001a0: 2074 6167 732e 0d0a 3c2f 703e 0d0a 2d2d tags...</p>..-- 00001b0: 2320 7669 6d3a 2065 7420 7377 3d34 2073 # vim: et sw=4 s 00001c0: 7473 3d34 0d0a ts=4.. 

复制版本:

 0000000: 4854 4d4c 2e53 6166 654f 626a 6563 740a HTML.SafeObject. 0000010: 5459 5045 3a20 626f 6f6c 0a56 4552 5349 TYPE: bool.VERSI 0000020: 4f4e 3a20 332e 312e 310a 4445 4641 554c ON: 3.1.1.DEFAUL 0000030: 543a 2066 616c 7365 0a2d 2d44 4553 4352 T: false.--DESCR 0000040: 4950 5449 4f4e 2d2d 0a3c 703e 0a20 2020 IPTION--.<p>. 0000050: 2057 6865 7468 6572 206f 7220 6e6f 7420 Whether or not 0000060: 746f 2070 6572 6d69 7420 6f62 6a65 6374 to permit object 0000070: 2074 6167 7320 696e 2064 6f63 756d 656e tags in documen 0000080: 7473 2c20 7769 7468 2061 206e 756d 6265 ts, with a numbe 0000090: 7220 6f66 2065 7874 7261 0a20 2020 2073 r of extra. s 00000a0: 6563 7572 6974 7920 6665 6174 7572 6573 ecurity features 00000b0: 2061 6464 6564 2074 6f20 7072 6576 656e added to preven 00000c0: 7420 7363 7269 7074 2065 7865 6375 7469 t script executi 00000d0: 6f6e 2e20 5468 6973 2069 7320 7369 6d69 on. This is simi 00000e0: 6c61 7220 746f 0a20 2020 2077 6861 7420 lar to. what 00000f0: 7765 6273 6974 6573 206c 696b 6520 4d79 websites like My 0000100: 5370 6163 6520 646f 2074 6f20 6f62 6a65 Space do to obje 0000110: 6374 2074 6167 732e 2020 596f 7520 7368 ct tags. You sh 0000120: 6f75 6c64 2061 6c73 6f20 656e 6162 6c65 ould also enable 0000130: 0a20 2020 2025 4f75 7470 7574 2e46 6c61 . %Output.Fla 0000140: 7368 436f 6d70 6174 2069 6e20 6f72 6465 shCompat in orde 0000150: 7220 746f 2067 656e 6572 6174 6520 496e r to generate In 0000160: 7465 726e 6574 2045 7870 6c6f 7265 720a ternet Explorer. 0000170: 2020 2020 636f 6d70 6174 6962 696c 6974 compatibilit 0000180: 7920 636f 6465 2066 6f72 2079 6f75 7220 y code for your 0000190: 6f62 6a65 6374 2074 6167 732e 0a3c 2f70 object tags..</p 00001a0: 3e0a 2d2d 2320 7669 6d3a 2065 7420 7377 >.--# vim: et sw 00001b0: 3d34 2073 7473 3d34 0a =4 sts=4. 

更新:根据对这个问题的评论,问题已经解决:

这很容易:第一个文件有CRLF行结束(窗口),第二个LF(Unix)。 util file (在git \ usr \ bin中可用)会告诉你( file ab会回复类似于a: ASCII text, with CRLF line terminators b: ASCII text

下面的原始答案:


您显示的差异显示一个不同的行。 你可以发布.git / config(或更好的git config -l )。

您可能会忽略一些空白忽略

您应该尝试禁用core.whitespace=fix,-indent-with-non-tab,trailing-space,cr-at-eol ;

 git show HEAD:myfile|md5sum md5sum myfile 

可以用来validation文件实际上是不同的。 使用外部差异也可以

 git show HEAD:myfile > /tmp/myfile.HEAD diff -u myfile /tmp/myfile.HEAD # or if you prefer an interactive tool like eg: vim -d myfile /tmp/myfile.HEAD 

我有同样的问题。 win-> lin copy之后,我已经修改了所有的文件。
我用fromdos来修复行尾
接着

 git add -uv 

添加更改。
它添加了3个文件(不是所有的),我实际上修改。 之后, git状态只显示3个修改的文件。 在git commit之后,一切正常

但是,即使内容完全相同,很多(如果不是每个)文件都显示为已修改。

使用git 2.8(2016年3月),您将能够快速检查这些更改是否与eol有关。

参见TorstenBögershausen ( tboegi ) 提交的a7630bd (2016年1月16日) 。
(由Junio C gitster合并- gitster – in commit 05f1539 ,2016年2月3日)

ls-files :添加eol诊断

在跨平台环境中工作时,用户可能需要检查文档文件是否在存储库中被标准化存储,以及.gitattributes是否被正确设置。

让Git能够显示索引和工作树中的行尾以及有效的text / eol属性。

行结束(“ eolinfo ”)显示如下:

 "-text" binary (or with bare CR) file "none" text file without any EOL "lf" text file with LF "crlf" text file with CRLF "mixed" text file with mixed line endings. 

有效的text / eol属性是其中之一:

 "", "-text", "text", "text=auto", "text eol=lf", "text eol=crlf" 

git ls-files --eol给出这样的输出:

 i/none w/none attr/text=auto t/t5100/empty i/-text w/-text attr/-text t/test-binary-2.png i/lf w/lf attr/text eol=lf t/t5100/rfc2047-info-0007 i/lf w/crlf attr/text eol=crlf doit.bat i/mixed w/mixed attr/ locale/XX.po 

以显示索引(' i ')和工作树(' w ')中的数据中使用的eol约定,以及显示的每个path的有效属性

我已经解决了这个问题,使用下面的stpes

1)从Git的索引中删除每个文件。

 git rm --cached -r . 

2)重写Git索引来获取所有新的结尾。

 git reset --hard 

解决scheme是在git站点上描述的步骤的一部分https://help.github.com/articles/dealing-with-line-endings/

你有没有改变文件的模式? 我在我的机器上做了,本地开发机器有777给所有的文件,而回购有755显示每个文件被修改。 我做了git diff ,它显示旧模式和新模式是不同的。 如果这是问题,那么你可以通过git config core.filename false轻松地忽略它们
干杯

我能够通过将core.autocrlf从false更改为core.autocrlf = input来修复Windows机器上的问题

 git config core.autocrlf input 

https://stackoverflow.com/a/1112313/52277中的build议;

Git FAQ有一个可能相关的答案,虽然我从来没有遇到过这个问题:

为什么git diff有时列出一个没有改变的文件?

git diff和其他git操作是优化的,所以它甚至不会查看磁盘上和git索引中的状态(大小,修改时间等)不同的文件。 这使得git diff变化非常快。 如果文件已被触摸,git diff必须查看内容并进行比较,即使实际上没有变化,操作也是非常慢的。 git diff会列出这些文件,提示它没有得到最佳使用。 运行git状态不仅会显示状态,而且还会更新索引状态,对于未更改的文件磁盘进行后续操作,不仅差异更快。 导致许多文件被diff列出的典型情况是运行批量编辑命令,比如perl -pi -e'…'。

git status显示给你什么?

复制我的本地存储库和工作副本到另一个文件夹(顺便说一下,在Windows上),我有四个文件,不断显示为已更改,并尝试其他答案中列出的每个build议。 到底是什么修复了我,是删除本地分支,再从远程下载。 在我的情况下,我想这与复制本地存储库而不是克隆有关。

所以,我在这里尝试了一切,想要提供一个解决所有问题的解决scheme。 我的问题不是线路结尾或实际的权限或类似的东西。 这是因为我已经安装了Cygwin以及随之而来的大量东西,而我不知道的东西也安装了它自己的git版本。 我从来没有注意到这一点,只是我遇到了奇怪的问题,用户和文件被标记为已更改(因为烫发更改)。

事实certificate,我想到了这一点,因为我认为我应该只是更新Git的最新版本,我做了,但运行git --version返回旧的版本号。 在随后寻找原因之后,我在我的环境path中find了cygwin bin目录的根目录,其中包含一个运行在旧版本号的git可执行文件。 去搞清楚。

这也很难find,因为我安装了TortoiseGit。 由于path回退,我的命令行工具将使用cygwin版本,并且TortoiseGit被configuration为使用windows版本,使得它更加混乱。

希望这有助于某人。

在你的configuration唯一可疑的条目在我看来是core.ignorecase 。 你可以尝试用下面的方法来解除它:

  git config --unset core.ignorecase 

…看看git statusgit diff的输出是否不同。

如果你有多个分支并且所有的改变都被推送了,那么这个解决scheme可能工作

只需添加并提交您所看到的所有更改到当前分支(如主)。 然后签出另一个分支(比如testing)。 本地删除主分支(使用-D选项)。 从git中拉出主分支

完成了!