If you want to destroy all changes since a given commit, you can reset the branch you are working on (for example master) to the commit. What git reset <commit>
does is that it moves your HEAD
to the given commit. The following commits get discarded.
A---B---C---D-master
then
git reset --hard <SHA1-of-B>
gives you:
A---B-master
--hard
is for discarding your recent changes from the index and your local files.
If you have multiple branches, this might get a bit more complicated, but you get the idea.
Note that the discarded commits may be recoverable with git reflog
, but you won't be likely to see them if you're not trying to. Eventually, the discarded commits will disappear for good, especially if you're using git gc
now and then.