Search code examples
githubgit-revert

How to revert a pull request commit on GitHub


I am trying to revert my latest commit on GitHub. All the information I have looked through says that there should be a revert button in the pull request but I do not see it, and cannot find it.

Is there anyway to do this on GitHub? Or could I do it terminal with a few rebase commands?


Solution

  • Assuming this pull request merge is a commit merge (what I would expect), then you may try the following from the Git bash:

    git checkout your_branch
    git revert <hash of merge commit> -m 1
    git push origin your_branch
    

    This solution assumes that you want to revert back to the branch into which the pull request merge was made. If you want to follow the incoming branch, then use -m 2 instead.

    To find the SHA-1 hash of the merge commit, you may use git log, and then copy over the hash from the first commit, which should appear at the top.

    Note that nuking the merge commit and then doing a force push is generally a bad idea here. The reason it is bad is because your branch is published on GitHub. This means that rewriting the history of that branch could cause problems for anyone besides you who happens to be sharing this branch.