Git checkout不会丢弃我的更改。

4

我正在使用cygwin上的Windows XP系统中的git 1.7.1版本。 下面通过一个例子来更好地说明这个问题:

$ git status
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   system/application/config/email.php
#       modified:   system/application/config/upload.php
#       modified:   system/application/views/frontend/business_subscription/start_subscription.php
#
no changes added to commit (use "git add" and/or "git commit -a")

$ git checkout system/application/config/email.php

$ git status
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   system/application/config/email.php
#       modified:   system/application/config/upload.php
#       modified:   system/application/views/frontend/business_subscription/start_subscription.php
#
no changes added to commit (use "git add" and/or "git commit -a")

$ git diff -w

Git显示列出的文件中有一些更改,但我无法摆脱这些更改-该文件仍然存在。

似乎只发生在除空格之外没有其他更改的文件上(因为git diff -w不输出任何内容)。

我认为这可能是由于git的crlf设置引起的,但我对此不确定。


git config --list: core.autocrlf=input core.safecrlf=false - fest
如果你执行 git add system/application/config/email.php 会发生什么? - CB Bailey
1个回答

4
任何导致内容(即直接作为文件存储在磁盘上的“工作目录”中)与索引不同的结帐文件都意味着某种“自动内容转换”已经发生。
可能是自动crlf设置(我建议将其设置为false),也可能是过滤驱动程序(具有smudge/clean脚本)。

1
看起来问题确实是由core.autocrlf引起的。当我将其设置为false时,更改就不会出现了。我想现在是时候将整个存储库和我的开发团队转换为使用一致的换行符了。 - fest
@fest:是的,那就是这个想法。另请参阅 https://dev59.com/unE95IYBdhLWcg3wY85l#2354278 - VonC

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