I have a source tree with git and I need to reverse all my changes that I have done since September, I know the id of the commit, and I can also generate a list of commits that I want to revert with git rev-list, the question is how do I feed that list to git so that it uncommits all of them?
Or if there is a better way to do this I would really app开发者_如何学JAVAreciate it.
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.
精彩评论