Revert a merge commit from a protected branch on GitHub.com

Reverting on GitHub

You don't need to restore (undelete) branches on GitHub to revert merge commits resulting from pull requests. For example:

Revertable pull request

Non-revertible pull request

Sometimes the revert button doesn't appear. From GitHub Help on reverting a pull request:

Note: You may need to use Git to manually revert the individual commits if:

  • Reverting the pull request causes merge conflicts
  • The original pull request was not originally merged on GitHub (for example, using a fast-forward merge on the command line)

It took me a while to find an example, but if the head branch wasn't merged into the base branch using the big green button on GitHub then it can't be reverted on GitHub:

Non-revertable pull request

git revert

Locally on the command line, you can use the git revert command to revert changes.

This will work on both your protected branch and a downstream branch. git revert creates a new commit ahead of the current HEAD so you don't need to force push, and if from a downstream branch, you can manually create a pull request for the reverted changes.

Reverting a merge commit is slightly more complicated than reverting a single-parent commit, so I'd suggest taking a look at this question for more information, as it's something I've never done before.

If people aren't comfortable using the command line, I think SourceTree has an item on the context menu to revert a commit but I don't know how it handles merge commits. There might be similar options in other GUI applications.

Hope this helps!


The most easiest option is to perform the following

git revert -m 1 "last_commit_id"