Search code examples
gitgithubmergegit-revert

Git Revert a Revert for a Merge


I had a feature branch created, let's say feature/branch1 on github. I created a pull request for it and got it merged. Initial PR Merge Commit

When it reached our pipeline, we figured there was a problem and we got it reverted using the Revert button on Git This created a "Revert" PR that we merged with the master and all was well. Reverted Merge Commit

After a few weeks, post other PRs that got merged into the master, we figured we would revert-the-revert. This time, we went into the Revert PR that was closed and tried to use the Revert button again. But we got this error message

Sorry, this pull request couldn't be reverted automatically. 
It may have already been reverted, or the content may have changed since it was merged.

How do I get this revert done?

The most ideal situation I would like to have, is to have a new branch that contains the revert of the revert, so I can make further changes and go back through the PR process.


Solution

  • The error which you see is artificial check of github, which I personally find unneeded. You can revert the revert locally then:

    git fetch origin master
    git checkout origin/master (or reset)
    git revert <REVERT HASH>
    git push origin master
    

    This should succeed, modulo conflicts with changes done since the revert.

    PS: actually, the error could be because of the conflicts.