Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git checkout does not reset file

Tags:

git

Running Windows 7 with Git installed from Git-1.8.3-preview20130601.exe.

I have a modified file in my working dir, I'd like to restore it to its state at the last commit. I have tried various invocations of git checkout, but the modified file remains in my working dir. For example:

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

(I get the same result with git checkout -- pomodoro.html.)

So, git thinks pomodoro.html is modified, but when I use

git difftool  

I'm told the files are identical.

Don't know if it's relevant, but I have core.autocrlf set to true in my Git config. When I changed it to false I got the same behavior, though.

like image 561
Number8 Avatar asked Jul 14 '13 18:07

Number8


1 Answers

This link (provided by AD7Six) -- help.github.com/articles/dealing-with-line-endings -- seems to be the answer: fix up the line endings.
Since autocrlf has been set to true, not sure how the line endings in that one file got messed up.
Thanks for all the other comments.

like image 195
Number8 Avatar answered Oct 14 '22 22:10

Number8