How to undo a merge on Bitbucket?

亡梦爱人 提交于 2019-12-31 08:34:11

问题


I've created a merge (into the 'master' branch) that's now on a Bitbucket repo. Long story short: I need to undo that merge.

I know that you can do this at the Github site itself, but Bitbucket doesn't have that feature. I'm not clear on how to do this with Git without causing a mess.


回答1:


You need to first clone the repository on your local system (you can get the repo URL in SSH or HTTPS format from the "Overview" page of the repository in Bitbucket):

git clone git@bitbucket.org:my/repo.git
-or-
git clone https://my@bitbucket.org/my/repo.git

git checkout master

.. then revert the most recent commit. First list the available commits with:

git log

.. then select the commit before the merge:

git reset --hard 72ead1c4c1778c23c277c4f15bbb68f3bb205f54

.. where the hash is the hash of the commit before the merge (from the log). Finally, force-push the changes back to Bitbucket, overwriting history.

git push -f

Naturally if the repo is shared, and its other users have pulled your most recent commit and built atop it, they won't be happy. So in that case be sure to notify everybody of what you're doing.

revert, as mentioned in the other answers is another option; it keeps the commit you made, but modifies the repository further (with a new commit) in such way that it undoes the changes you made. Whether you want to use revert depends on whether you want the information in your commit to remain in the repo history or not.

For more detail on undoing changes in git, see a good tutorial page by Atlassian.




回答2:


A "Revert pull request" feature was implemented in Bitbucket in 2017.

To revert a pull request:

  1. From the pull request, click the Revert button in the top right. (Optional) From the Revert pull request dialog, change the Branch name for the new branch you're about to create.
  2. Click the Revert button. Once you click Revert, Bitbucket creates the new branch. Even if you cancel the pull request, the revert branch remains in the repository.
  3. The Create a pull request page opens with the revert branch as the source. After you add your reviewers and make additional changes, click Create.

Source: the docs.




回答3:


I would suggest doing a revert instead, since you are reverting a public repo.

git revert HEAD
git push -f origin



回答4:


to undo the changes of a commit: git revert <commit id>



来源:https://stackoverflow.com/questions/37036381/how-to-undo-a-merge-on-bitbucket

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!