Discarding my changes and going back to an old commit

968 views Asked by At

I'm working on my project in Sublime text. After reaching a milestone earlier, I committed my work to my local Git (didn't Push)

I continued working, and screwed up. Now I want to go back to my last commit and try again. So I Googled a bit and found the git revert --hard last-commit which I entered in my command prompt and got this

HEAD is now at 5d6eebd Revert "Finished adding feature. Everything works"

But in my Sublime editor, my files haven't changed back. I tried closing and reopening the files but everything is still screwed up.

What's the point of reverting if it doesn't change my files back? Am I doing something wrong?

2

There are 2 answers

0
Thomas Foster On

git revert is for making a new commit that undoes the work of a previous commit (or range of commits).

To get back to your last commit on the current branch, discarding all work done since then, try git reset --hard HEAD.

2
Mart Dominguez On

What you do with revert it's cancel the commit.

If you want use the branch "5d6eebd" do a checkout.

If not if you want to destroy local changes use reset.

Revert documentation ( http://git-scm.com/docs/git-revert ) says "If you want to throw away all uncommitted changes in your working directory, you should see git-reset[1], particularly the --hard option."

In another thread here you have some samples How to revert Git repository to a previous commit?