'Files not restored after git reset --hard

I am trying to rollback all my commits and files to a specific commit. I want to get rid of all the changes I did and all the files that were created from that specific commit onwards.

I tried rolling back using:

git checkout #commit_to_restore_to
git reset --hard #commit_to_restore_to

I get a confirmation that HEAD is now at #commit_to_restore_to "Commit_message"

However, my files are exactly the same as before. How can I rollback all my files?

I am on Ubuntu 12.10.

Here is more information:

$ git status
<<fill this in>>

# git diff --name-status #commit_to_restore_to  #provide real commit number please.
<<fill this in too>>
git


Solution 1:[1]

I feel so embarrassed. The files were changing, the problem is that the folders weren't. Since my .gitignore has (e.g.) pyc files, the folders that I had created post commit were still there because they had those files in it. I was just doing an ls on the dir and going insane for since the same tree structure kept showing up.

Sorry about that and thank you!

Solution 2:[2]

The easy way to rewrite a branch ref is

git branch -f mastercommit

if you're on that branch at the moment you can

git checkout -B mastercommit

Solution 3:[3]

If you checkout a commit then you have the contents of your repository as of that commit in your working directory. There is thus nothing to reset. There would be something if you did instead:

$ git checkout <commit>
# muck with files; do some other git stuff
$ git reset --hard <commit>

In the above case reset will actually do something.

It sounds like what you really want is to forget everything after commit and then to continue development. If so, this works (assume you are on the master branch):

$ git checkout -b tmp-branch <commit>
$ git branch -d master
$ git branch -m tmp-branch master

and you will want to be careful with the above.

Solution 4:[4]

Careful! When you did git checkout SHA you ended up on a floating branch. git status should say something like:

# Not currently on any branch.

There was also a warning from git checkout. If you wanted to reset your master branch with git reset --hard SHA you want to move back to that branch first with git checkout master.

Solution 5:[5]

For me as workarounds I found:

git rm --cached -r . 

git reset --hard

and sometimes only: git ls-files -m | xargs -I {} git update-index --assume-unchanged {}

But this didn't fix the root problem.

I found that a setting from .gitattributes generated the problem:

I had *.bat text eol=crlf that was enforcing bat files in Windows having eol=crlf.

I commented that setting:

#*.bat text eol=crlf

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 nitochi
Solution 2 jthill
Solution 3
Solution 4 Ben Jackson
Solution 5