即使使用autocrlf = false,git status也会显示修改

cod*_*zen 35 git revert git-status core.autocrlf

我遇到了与此问题相同的问题:git status显示修改,git checkout - <file>不会删除它们

Git继续显示工作目录修改,即使git config --global core.autocrlf false:

E:\_dev\github\Core [master +0 ~93 -0]> git config --get-all core.autocrlf
false
false
Run Code Online (Sandbox Code Playgroud)

(注意我甚--system至将设置设置为false)

为什么看起来Git仍在修改我的行尾?

试图摆脱修改

底线

E:\_dev\github\Core [master +0 ~93 -0]> 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:   tools/StatLight/StatLight.EULA.txt
... more changes ...
no changes added to commit (use "git add" and/or "git commit -a")
Run Code Online (Sandbox Code Playgroud)

git checkout - .

E:\_dev\github\Core [master +0 ~93 -0]> git checkout -- .
E:\_dev\github\Core [master +0 ~93 -0]> 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:   tools/StatLight/StatLight.EULA.txt
... more changes ...
no changes added to commit (use "git add" and/or "git commit -a")
Run Code Online (Sandbox Code Playgroud)

偶尔会以奇怪的方式产生影响:

E:\_dev\github\Core [master +0 ~628 -0]> git checkout -- .
E:\_dev\github\Core [master +0 ~361 -0]> git checkout -- .
E:\_dev\github\Core [master +0 ~93 -0]> git checkout -- .
E:\_dev\github\Core [master +0 ~93 -0]> git checkout -- .
E:\_dev\github\Core [master +0 ~93 -0]> git checkout -- .
Run Code Online (Sandbox Code Playgroud)

git reset --hard

E:\_dev\github\Core [master +0 ~93 -0]> git reset --hard
HEAD is now at 11a7f9a Merge pull request #8 from RemiBou/master
E:\_dev\github\Core [master +0 ~93 -0]>
Run Code Online (Sandbox Code Playgroud)

git add.; git stash; git stash drop

E:\_dev\github\Core [master +0 ~93 -0]> git add .
... warnings ....
warning: CRLF will be replaced by LF in tools/StatLight/StatLight.EULA.txt.
The file will have its original line endings in your working directory.

E:\_dev\github\Core [master +0 ~93 -0]> git stash
Saved working directory and index state WIP on master: 11a7f9a Merge pull request #8 from 
RemiBou/master
HEAD is now at 11a7f9a Merge pull request #8 from RemiBou/master

E:\_dev\github\Core [master +0 ~93 -0]> git stash drop
Dropped refs/stash@{0} (de4c3c863dbad789aeaf563b4826b3aa41bf11b7)

E:\_dev\github\Core [master +0 ~93 -0]> git status .\tools\StatLight\StatLight.EULA.txt
# 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:   tools/StatLight/StatLight.EULA.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
Run Code Online (Sandbox Code Playgroud)

Bre*_*els 19

这似乎是msysgit中的错误.要解决此问题,请尝试创建包含的.gitattributes文件

* -text
Run Code Online (Sandbox Code Playgroud)

这将告诉git不要对任何文件执行EOL转换.

  • 似乎错误不仅限于msysgit.可以在Mac OS X上轻松复制:http://stackoverflow.com/questions/22823004/files-incorrectly-reported-modified-git-attributes-buggy-leading-to-inconsist (2认同)

Von*_*onC 10

检查您是否没有.gitattributes文件

手册页"效果"部分所述gitattributes,这些文件也可能对eol和自动转换产生影响:

text ^^^^^^
Run Code Online (Sandbox Code Playgroud)

此属性启用并控制行尾标准化.
对文本文件进行规范化后,其行结尾将转换为LF存储库中的文件.
要控制工作目录中使用的行结束样式,请对单个文件使用eol属性,core.eol对所有文本文件使用配置变量.

检查您的配置core.eol,如" 如何git core.autocrlf在不同操作系统之间使用行结束转换 "中所述.


小智 7

我正在调查MSysGit中core.autocrlf的奇怪行为,我发现:

[core]
    autocrlf = false
    safecrlf = true
    ignorecase = true
    eol = native 
Run Code Online (Sandbox Code Playgroud)

在全局配置文件和从另一台PC复制的repo中没有core.autocrlf设置(未克隆,仅复制),发出 git status命令会导致所有文本文件被标记为已修改(没有gitattributes around).

但是,如果将本地(存储库)core.autocrlf设置添加为true,然后发出git status命令,则所有更改都将消失,并且存储库将变为干净.

但是(这是奇怪的行为)如果从存储库配置文件中删除刚添加的core.autocrlf设置(从而返回到确切的初始状态),git status命令将继续报告没有更改!

鉴于没有对存储库执行任何操作,只更改配置设置,并恢复到原始状态,已经完成了这个诀窍......

如果这不是一个错误,我无法想象世界上谁可以称之为"正常"行为.


Cri*_*ero 5

此问题可能是由gitattributes的文本选项引起的.

请仔细阅读文档,但基本上autocrlf只有在text未设置的情况下才有意义.gitattributes:

未指定
如果文本属性是未指定的,GIT中使用core.autocrlf配置变量,以确定是否该文件应转换.

.gitattributes通过以下方式查找文件

find <root-dir> -name .gitattributes
Run Code Online (Sandbox Code Playgroud)

greptext,eol或者crlf找到你的罪魁祸首,并根据需要修改.

您可以只更改此文件并还原更改,而无需提交足够长的时间来解决您的问题.