git签出不会重置文件

git签出不会重置文件,git,Git,运行Windows 7并从Git-1.8.3-preview20130601.exe安装Git 我的工作目录中有一个修改过的文件,我想将它恢复到上次提交时的状态。我尝试了各种调用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 b

运行Windows 7并从Git-1.8.3-preview20130601.exe安装Git

我的工作目录中有一个修改过的文件,我想将它恢复到上次提交时的状态。我尝试了各种调用
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>
我听说文件是一样的


不知道它是否相关,但我在Git配置中将
core.autocrlf
设置为
true
。当我将其更改为
false
时,我得到了相同的行为。

这是一个疯狂的尝试,但是:

该文件是否因某种原因在repo中标记为可执行文件?html不太可能,但如果它存储在fat格式的驱动器上,则它是可以想象的。如果是这种情况,并且您的windows git未配置为忽略权限,则文件将始终被更改,因为在windows上,任何重置或签出操作都不会为您提供可执行位

要将消息集filemode设置为false:

此链接(由AD7Six提供)——help.github.com/articles/detaining-with-line-endings——似乎就是答案:修复行尾。
由于autocrlf已设置为true,因此无法确定该文件中的行尾是如何弄乱的。

谢谢所有其他的评论

我在osx上遇到了类似的问题,这是由于两个文件同名但大小写不同:

我花了几个小时试图找出如何修复它,按照如下说明进行操作。识别两个同名文件的症状的关键是,当您对这些文件执行git签出时,您将看到下一个git状态中列出的文件,但是该文件的情况不同。我最终删除了这些文件,然后又重新添加了其中一个

git rm -f <filename>
git rm -f <filename>
git commit -m "Removing duplicate files"
<put the file back, the version you want>
git add . 
git commit -m "adding files back"
git rm-f
吉特rm-f
git commit-m“删除重复文件”
git添加。
git commit-m“将文件添加回”

@markusuenterwaditzer他试过了。
git checkout pomodoro.html
将从索引而不是从提交中检出文件-如果您已经添加了更改,这可能是罪魁祸首。要还原文件,我会尝试
git checkout HEAD pomodoro.html
@millimoose:我还没有提交更改,我只想撤消未保存的更改。“git checkout HEAD pomodoro.html”也不起作用……也许索引与repos不同步。?@Number8不知道,不知道如果没有重现问题的方法,还有很多事情要做。我使用带有可执行标记的文件,它们在windows的git中很好。因此没有问题(唯一的问题是当我想创建一个可执行文件时,我没有在windows中找到方法,所以我在一些unix中签出、设置、提交和推送)。也许这在过去有所改进。几年前,我对这件事有意见。让我们等待原作者的回复,如果他只是不知道重置或如果有一些真正的问题。我只是有一个PDF的问题。当用git上传时,它看起来有点歪,但通过FTP看起来还不错。最后,我发现我无法通过结帐或储存来摆脱它,这把我带到了这里,解决了所有问题。谢谢。请注意,在已经弄乱文件之后正确设置配置将没有帮助。在这种情况下,我建议删除自动修改的文件,然后再次签出它们。现在,更新的配置应该可以帮助您避免这场噩梦。
git rm -f <filename>
git rm -f <filename>
git commit -m "Removing duplicate files"
<put the file back, the version you want>
git add . 
git commit -m "adding files back"