How to make GIT ignore my changes

Although the title seems similar to previous questions, I could not find the solution to to my Simple case:

  • I committed to my branch 'ABCD' : git commit -a .....
  • Then decided to visit a previous commit so : git checkout 2387687326487
  • Here I made some changes which was for testing purpose only, and I don't want to keep them
  • I am done, I want to get back to my latest commit(again:ignoring changes whcih i made to the old commit) : the command git checkout 'ABCD' gives error:

Your local changes to the following files will be overwritten by checkout....please commit or stash...

while I don't want to commit or stash or whatever. I just want to go back home :) what should I do please?


Using just

git checkout .

will discard any uncommitted changes in the current directory (the dot means current directory).

EDIT in response to @GokulNK:

If you want to keep those changes for future use, you have 2 options:

  • git stash: this will save those changes in a stack. You can apply the changes to your working copy later using git stash pop
  • git diff > changes.patch: This will save those changes to the file changes.patch. If you want to apply them to your working copy you can do so: git apply changes.patch.

If you are sure that you don't want to keep your changes, the following line will do :

git checkout -f 'ABCD'

Option '-f' stands for force.


To undo local changes and go back to the state from the commit you can:

git reset --hard

Apart from the mentioned solutions you can stash the changes

git stash

Checkout your branch

git checkout 'ABCD'

And eventually, when you are sure that you don't need anything from the stashed changes, and have checked twice with gitk or gitg, throw away the stash:

git stash drop

That is my preferred way, as it is safer.