运行安装了Git的Windows 7 Git-1.8.3-preview20130601.exe.
我的工作目录中有一个修改过的文件,我想在最后一次提交时将其恢复到状态.我尝试了各种调用git checkout,但修改后的文件仍保留在我的工作目录中.例如:
[C:\Work\BitBucket\proj1] 14:32:45>git status
On branch work2
Your branch is behind 'origin/work2' by 9 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
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: pomodoro.html
no changes added to commit (use "git add" and/or "git commit -a")
[C:\Work\BitBucket\proj1] 14:32:53>git checkout pomodoro.html
[C:\Work\BitBucket\proj1] 14:33:00>git status
On branch work2
Your branch is behind 'origin/work2' by 9 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
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: pomodoro.html
no changes added to commit (use "git add" and/or "git commit -a")
[C:\Work\BitBucket\proj1] 14:33:04>
Run Code Online (Sandbox Code Playgroud)
(我得到了相同的结果git checkout -- pomodoro.html.)
所以,git认为pomodoro.html被修改,但是当我使用时
git difftool
Run Code Online (Sandbox Code Playgroud)
我被告知文件是相同的.
不知道它是否相关,但我已经core.autocrlf设置为true我的Git配置.当我改变它时,false我得到了同样的行为.
这个链接(由AD7Six提供)-help.github.com/articles/dealing-with-line-endings-似乎是答案:修复行尾。
由于autocrlf已设置为true,所以不确定该文件中的行尾如何弄乱。
感谢所有其他意见。
这是一个疯狂的镜头,但是:
该文件是否出于某种原因在存储库中标记为可执行文件?对于 html 来说这是不可能的,但是如果它已经存储在例如 fat 格式化驱动器上,那么这是可以想象的。如果是这种情况,并且您的 Windows git 未配置为忽略权限,则该文件将始终被更改,因为没有多少重置或签出将为您提供 Windows 上的可执行位。
要摆脱消息,请将 filemode 设置为 false:https ://superuser.com/a/139044/236874