Git展示修改的文件但我没有做任何更改,Git重置无效。

9

我克隆了代码库并切换到我的分支,当我打印git状态时,我看到修改的文件。我尝试做git reset --hard但没有效果 :((

git status
On branch release

Changes not staged for commit:

    modified:   htdocs/fonts/OfficinaSansBoldC.eot
    modified:   htdocs/fonts/OfficinaSansBoldC.svg
    modified:   htdocs/fonts/OfficinaSansBoldC.ttf
    modified:   htdocs/fonts/OfficinaSansBoldC.woff
    modified:   htdocs/fonts/OfficinaSansC-Book.eot
    modified:   htdocs/fonts/OfficinaSansC-Book.svg
    modified:   htdocs/fonts/OfficinaSansC-Book.ttf
    modified:   htdocs/fonts/OfficinaSansC-Book.woff

no changes added to commit 

git reset --hard origin/release

git status
On branch release

Changes not staged for commit

    modified:   htdocs/fonts/officinasansboldc.eot
    modified:   htdocs/fonts/officinasansboldc.svg
    modified:   htdocs/fonts/officinasansboldc.ttf
    modified:   htdocs/fonts/officinasansboldc.woff
    modified:   htdocs/fonts/officinasansc-book.eot
    modified:   htdocs/fonts/officinasansc-book.svg
    modified:   htdocs/fonts/officinasansc-book.ttf
    modified:   htdocs/fonts/officinasansc-book.woff

no changes added to commit 

1
请在正文中解释您的问题。 - jub0bs
git clean -df 没有帮助。 - Ivan
在你的问题中,你写成了 autoclrf ,但正确的键是 core.autocrlf (请注意 "r" 和 "l" 互换了)。这是你问题中的笔误还是配置文件中的笔误?你手动编辑过你的配置文件吗? - jub0bs
diff --git a/htdocs/fonts/officinasansc-book.woff b/htdocs/fonts/officinasansc-b index f65eecc..11f16fa 100644 二进制文件 a/htdocs/fonts/officinasansc-book.woff 和 b/htdocs/fonts/officinas - Ivan
显示剩余3条评论
3个回答

10

在使用core.autocrlf输入时存在一个问题,即它可以改变行尾字符(eol)即使对于不应被更改的(二进制)文档也是如此。

建议:

git config --global core.autocrlf false
git clone /url/your/repo

意思是再次克隆你的 repo 并查看这些差异是否仍然存在。


使用 Git 2.8 (2016年3月),您可以快速检查这些更改是否与行尾有关。

请参见commit a7630bd(由 Torsten Bögershausen (tboegi) 在 2016年1月16日提交)。
(由 Junio C Hamano -- gitster --commit 05f1539 于 2016年2月3日合并)

ls-files: 添加行尾诊断功能

在跨平台环境中工作时,用户可能希望检查文本文件是否以规范化方式存储在存储库中,并且 .gitattributes 是否设置正确。

使 Git 能够显示索引和工作树中的行尾以及有效的文本/行尾属性。

行尾 ("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约定以及对于每个显示的路径生效的属性。

2
这对我很有帮助,我不必再克隆存储库了。 - gary69
如果有疑问,"再次克隆您的存储库" - Ben Incani

4
我也遇到了同样的问题。 当我运行命令 git diff 时,结果如下:
Binary files a/app/webroot/font-awesome-4.4.0/fonts/fontawesome-webfont.ttf and b/app/webroot/font-awesome-4.4.0/fonts/fontawesome-webfont.ttf differ
warning: CRLF will be replaced by LF in app/webroot/font-awesome-4.4.0/fonts/fontawesome-webfont.ttf.
The file will have its original line endings in your working directory.

我尝试使用git reset --hard .命令,但是没有起作用。但是当在.gitattributes文件中添加*.ttf binary时,该命令生效了。

加油!


对我来说,将 *.svg binary 添加到 .gitattributes 并执行 reset --hard 也有帮助。很奇怪。 - Alex78191
我需要提交.gitattributes的差异,并删除和添加.ttf文件,以便在git版本2.21.0(Apple Git-120)中正常工作。 - Roger Campanera

0

无法工作的原因是传递给 Git 的行结束信息冲突。请尝试:

git ls-files --eol | grep /path/to/problematic/file

您可以在.git/info/attributes文件中添加一行来缓解这个问题。有关详细信息,请参见我的答案此处


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接