Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Revert a merged pull request on Bitbucket

I've created a pull request and I've merged it to an wrong branch. How can I revert it?

As far I've been to figuring out taking a look over there, I'm able to hard reset the destination branch... but, how about the pull request in origin repository?

I'm using Bitbucket and I've created the pull request from SourceTree (opening the Bitbucket page).

I've three branches I'm working on: master, dev and create-alias. create-alias was set up from dev and dev from master: master -> dev -> create-alias. The problem is I made a pull request from create-alias and I did merge it into master instead of dev.

I'm working on create-alias branch right now. The last commit on create-alias is 6ee20f9 and the merged commit on master is be36f72.

Could you write me down a bit about who to step-by-step revert it?

As far I've been able to figure out:

  1. checkout on master.
  2. revert -m 1 6ee20f9.
  3. push.
  4. checkout on create-alias and going on working.

Isn't it?

like image 335
Jordi Avatar asked Jul 11 '16 08:07

Jordi


People also ask

Can you reopen a merged pull request?

Simply - you can't re-open it.

What happens when a pull request is merged?

Merging occurs once a developer's submitted pull request has been approved by the repository maintainer. Before merging, the repository maintainer will need to review the developer's completed work. They will comment on any issues, and request edits from the developer as needed.

How do I revert changes in Bitbucket?

On Bitbucket, go to the repository settings, and change the "Main branch" to master_temp (on Github, change the "Default branch"). Now go to Bitbucket, and you should see the history that you want. You can now go to the settings page and change the Main branch back to master .


1 Answers

Unfortunately, there is no "Revert Pull Request" feature on Bitbucket as of this writing, but a feature request exists for it.

Note: Before you proceed, make sure your working copy is clean, with no uncommitted or unpushed changes.

So, you'll have to revert the merge in Git. First, find the SHA hash of the merge commit.

On the command line, this is:

git checkout <branch> git pull git log 

Then, we revert the merge commit and push it:

git revert -m 1 <SHA-1> git push 

In SourceTree, first checkout the branch in question, then Pull. Find the merge commit in the log window, then right click it, and click Copy SHA-1 to Clipboard.... Then go to Actions --> Open in Terminal. Once the terminal opens, type:

git revert -m 1 <SHA-1 (from clipboard)> git push 

Unfortunately, SourceTree doesn't have a way to simply right-click and revert a merge, but a feature request exists for it.

like image 196
Will Avatar answered Sep 16 '22 21:09

Will