38

我遇到了与这个问题相同的问题:git status shows modify, git checkout -- <file> doesn't remove them

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

E:\_dev\github\Core [master +0 ~93 -0]> git config --get-all core.autocrlf
false
false

(请注意,我什--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")

混帐结帐 - 。

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

有时这会以一种奇怪的方式产生影响:

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 -- .

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]>

混帐添加 .; 混帐藏匿;git 存储下降

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

6 回答 6

22

这似乎确实是 msysgit 中的一个错误。作为一种解决方法,请尝试创建一个.gitattributes文件,其中包含

* -text

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

于 2013-03-01T15:39:37.580 回答
10

检查您是否没有.gitattributes文件

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

text ^^^^^^

此属性启用和控制行尾标准化。
当一个文本文件被规范化时,它的行尾被转换为LF存储库中的。
要控制工作目录中使用的行尾样式,请对单个文件使用 eol 属性,core.eol对所有文本文件使用配置变量。

还要检查您的配置core.eol,如“如何git core.autocrlf在不同操作系统之间进行行尾转换”中所述。

于 2012-06-13T09:14:25.200 回答
7

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

[core]
    autocrlf = false
    safecrlf = true
    ignorecase = true
    eol = native 

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

但是,如果您将本地(存储库)core.autocrlf设置添加为 true,然后发出git status命令,所有更改都会消失,存储库会恢复为 clean

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

鉴于尚未对存储库执行任何操作,仅更改配置设置并恢复到原始状态就可以了...

如果这不是错误,我无法想象世界上谁能称其为“正常”行为。

于 2013-12-03T11:18:28.457 回答
5

这个问题可能是由gitattributes 的 text 选项引起的。

请仔细阅读文档,但基本上autocrlf只有在text没有设置时才重要.gitattributes

未指定
如果未指定 text 属性,git 使用 core.autocrlf 配置变量来确定是否应该转换文件。

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

find <root-dir> -name .gitattributes

grepfor text, eolorcrlf找到你的罪魁祸首并根据需要进行修改。

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

于 2013-03-28T17:05:48.560 回答
1

“autocrlf”问题是多平台 repo 的典型问题(即在 linux 下的服务器上使用与 tortoisegit 的 samba 共享)

我意识到,有时(通常),它更像是一个“chmod”问题而不是 autocrlf 问题:-git status windows 显示挂起的修改-git status linux 什么也不显示

“模式更改 100755 => 100644 config/packager.xml”

检查您的“静态”文件是否不是 +x,(在这种情况下,tortoisegit 不会喜欢它)

于 2014-01-13T08:36:52.657 回答
0

虽然我不知道是什么导致了这种奇怪的行为,但我知道另一种丢弃可能有效的更改的方法。

警告!要非常小心,先做备份;这可能具有高度破坏性。

如果您关心的所有数据都提交到存储库中,您可以简单地删除工作目录中的所有内容(当然除了隐藏的 .git 目录)并运行git reset --hard HEAD以让 git 仅从存储库数据重新创建工作目录。

请记住在执行此操作之前仔细检查您是否没有任何 git 未跟踪的重要数据。检查未提交的更改是不够的git status- 请记住,从工作目录中删除所有文件也会删除您告诉 git 忽略的文件,并且它们不会被重新创建,git reset --hard HEAD因为它们根本没有被跟踪。

于 2013-02-14T22:45:56.463 回答