After git reset --hard
, git status
gives me files within the Changes not staged for commit:
section.
I've also tried git reset .
, git checkout -- .
and git checkout-index -f -a
, to no avail.
So, how can I get rid of those unstaged changes?
This seems to hit only Visual Studio project files. Weird. See this paste: http://pastebin.com/eFZwPn9Z. What is special with those files, is that in .gitattributes I have:
*.sln eol=crlf
*.vcproj eol=crlf
*.vcxproj* eol=crlf
Also, autocrlf
is set to false in my global .gitconfig
. Could that be somehow relevant?
git reset --hard resets your index and reverts the tracked files back to state as they are in HEAD. It leaves untracked files alone.
Suppose you staged a file with git add <file-name> and then did a hard reset with git reset --hard HEAD before committing. Afterward, you found out that the staged file is missing. In this case, also, you can recover the files. We can use the command git fsck to recover the files after a hard reset.
If you do git reset --hard <SOME-COMMIT> then Git will: Make your current branch (typically master ) back to point at <SOME-COMMIT> . Then make the files in your working tree and the index ("staging area") the same as the versions committed in <SOME-COMMIT> .
I had the same problem and it was related to the .gitattributes
file.
However the file type that caused the problem was not specified in the .gitattributes
.
I was able to solve the issue by simply running
git rm .gitattributes
git add -A
git reset --hard
I have resolved this problem using following steps
Remove every file from Git's index.
git rm --cached -r .
Rewrite the Git index to pick up all the new line endings.
git reset --hard
Solution was part of steps described on Configuring Git to handle line endings
Git won't reset files that aren't on repository. So, you can:
$ git add .
$ git reset --hard
This will stage all changes, which will cause Git to be aware of those files, and then reset them.
If this does not work, you can try to stash and drop your changes:
$ git stash
$ git stash drop
I've had the same problem and stash, hard reset, clean or even all of them was still leaving changes behind. What turned out to be the problem was the x file mode that was not set properly by git. This is a "known issue" with git for windows. The local changes show in gitk and git status as old mode 100755 new mode 100644, without any actual file differences.
The fix is to ignore the file mode:
git config core.filemode false
More info here
Okay, I've kind of solved the problem.
It seemed that the .gitattributes
file, containing:
*.sln eol=crlf
*.vcproj eol=crlf
*.vcxproj* eol=crlf
made the project files appear unstaged. I am clueless why that is, and I'm really hoping that someone privy to the ways of git will give us a nice explanation.
My fix was to remove these files, and to add autocrlf = false
under [core]
in .git/config
.
This does not amount to exactly the same thing as the previous configuration, as it requires every dev to have autocrlf = false
. I'd like to find a better fix.
EDIT:
I commented the incriminating lines, uncommented them and it worked. What the ... I don't even ... !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With