0

Just pulled a change that i'd like to reverse, what's the quickest way of rolling back one commit?

1

1 Answer 1

1
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.

Sign up to request clarification or add additional context in comments.

7 Comments

Will this rebase a user who pulled the commit?
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.
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?
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.
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.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.