结账后修改Git文件,重置--hard等,即使autocrlf设置为false [英] Git files modified after checkout, reset --hard, etc. even though autocrlf is set to false
问题描述
这是我的系统对话:
unrollme-dev-dan:views Dan $ git reset --hard HEAD
HEAD现在在3f225e9修正扫描标题
unrollme-dev-dan:views Dan $ git status
#在分支主机上
#没有为commit提交的更改:
#(使用git add< file> ...来更新将要提交的内容)
#(使用git checkout - < file> ...放弃工作目录中的更改)
#
#modified:app / signup / finish.html
#modified:app / signup / scan.html
#
我将autocrlf设置为false:
unrollme-dev-dan:展开网站Dan $ git config core.autocrlf
unrollme-dev-dan:展开网站Dan $
unrollme-dev-dan:展开网站Dan $ git config --global core.autocrlf
unrollme-dev-dan:unroll-website Dan $
而且我没有
unrollme-dev-dan:展开网站Dan $ fin d。 -name .gitattributes
[只有结果在不同的目录树中]
这是由 .gitattributes
一个等级引起的,正如下面的答案中指出的那样。
当我对 \r\\\
$>文件执行 od -c
时, C $ C>。我不知道他们应该是什么,据推测,他们应该以 \\\
结尾,这就是差异显示的原因。但我不明白的是,即使使用
autocrlf
false,这些文件如何在结帐时修改。
什么可以导致git修改除autocrlf之外的结帐文件?
这个问题可能是由gitattributes的文本选项
https://www.kernel.org/pub/software/scm/git/docs /gitattributes.html
这个问题可以通过临时编辑你的 .gitattributes
文件来解决项目文件夹。
更改 * text = auto
至#* text = auto
对文件行尾进行必要的更改并推送提交。然后,您可以在更改后再次启用它,或者选择其他可能更适合您项目的选项。
Here is my system dialogue:
unrollme-dev-dan:views Dan$ git reset --hard HEAD
HEAD is now at 3f225e9 Fix scan titles
unrollme-dev-dan:views Dan$ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: app/signup/finish.html
# modified: app/signup/scan.html
#
I have autocrlf set to false:
unrollme-dev-dan:unroll-website Dan$ git config core.autocrlf
unrollme-dev-dan:unroll-website Dan$
unrollme-dev-dan:unroll-website Dan$ git config --global core.autocrlf
unrollme-dev-dan:unroll-website Dan$
And I don't have any .gitattributes files messing this up:
unrollme-dev-dan:unroll-website Dan$ find . -name .gitattributes
[ only results are in different directory tree ]
This is caused by a .gitattributes
one level up as pointed out in answer below.
When I do an od -c
on the files it shows \r\n
. I don't know what they "should" be, presumably, they should end in \n
and that is why the diff is showing. But what I don't understand is how these files could possibly be modified on checkout even with autocrlf
false.
What can cause git modifying a file on checkout besides autocrlf?
This problem can be caused by gitattributes' text option https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
This problem can be fixed by temporarily editing your .gitattributes
file within your project folder.
change * text=auto
to #* text=auto
make the necessary changes to files line endings and push your commit. You can then enable it again after the change has been made, or alternatively select one of the other options that may better suit your project.
这篇关于结账后修改Git文件,重置--hard等,即使autocrlf设置为false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!