Just pulled a change that i'd like to reverse, what's the quickest way of rolling back one commit?
1 Answer
git reset --hard HEAD^
HEAD^ means "one before head" and is thus equal to HEAD~1 and means to throw away the most recent commit including all of its changes. If you just want to destroy the commit but keep the files changed remove the --hard switch.
If you intend to push your updated branch back to the remote containing the commit you undid better do not use git-reset as it modifies history. Use git revert HEAD instead. This creates a new commit which reverts all changes from the given commit.
7 Comments
David
Will this rebase a user who pulled the commit?
ThiefMaster
It will only affect your local repository. People shouldn't be pulling from that one. But yes, it modifies history and thus you shouldn't push to the remote you pulled from after deleting that commit. If you plan to do so better use
git revert HEAD which actually creates a new commit that undoes the old one.David
So in the case that this was pushed by a user and pulled to a live server. It would remove the commit (and restore files affected) by the pull back to commit state before, right?
ThiefMaster
If someone pushed something he shouldn't have pushed and you don't know that nobody else pulled it using
git-revert is the only good choice.David
I know for a fact that the remote server has been pulled with the commit in it. However it is the only push to the server over the last few days and is the latest commit. So you think revert is best? I want to just roll the remote server back to it's state before the pull from remote, but leave the commit otherwise untouched.
|