简体   繁体   English

如何撤消 Bitbucket 上的合并?

[英]How to undo a merge on Bitbucket?

I've created a merge (into the 'master' branch) that's now on a Bitbucket repo.我创建了一个现在位于 Bitbucket 存储库上的合并(到“主”分支)。 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.我知道您可以在 Github 站点本身执行此操作,但 Bitbucket 没有该功能。 I'm not clear on how to do this with Git without causing a mess.我不清楚如何在不造成混乱的情况下使用 Git 做到这一点。

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): 您需要首先克隆本地系统上的存储库(您可以从Bitbucket中存储库的“Overview”页面获取SSH或HTTPS格式的repo URL):

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. 最后,强制将更改推回Bitbucket,覆盖历史记录。

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; 如其他答案所述, revert是另一种选择; 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. 是否要使用revert取决于您是否希望提交中的信息保留在repo历史记录中。

For more detail on undoing changes in git, see a good tutorial page by Atlassian . 有关撤消git中的更改的更多详细信息,请参阅Atlassian的一个很好的教程页面

A "Revert pull request" feature was implemented in Bitbucket in 2017. 2017年,Bitbucket实施了“恢复请求”功能。

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. 单击Revert后,Bitbucket将创建新分支。 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 . 资料来源: 文档

I would suggest doing a revert instead, since you are reverting a public repo. 我建议做一个revert ,因为你正在恢复一个公共回购。

git revert HEAD
git push -f origin

撤消提交的更改: git revert <commit id>

First, on your local machine, on the branch you merged into (eg master ):首先,在您的本地机器上,在您合并到的分支上(例如master ):

git revert -m 1 HEAD

or:或者:

git revert -m 1 <merge commit hash>

Then push to origin.然后推到原点。

Alternatively, if you cannot push directly to master, create a new branch off of master first before reverting, then push and create a new PR with this new branch against master and merge on bitbucket.或者,如果您不能直接推送到 master,请在恢复之前先从 master 上创建一个新分支,然后使用这个新分支推送并创建一个新的 PR 并针对 master 并在 bitbucket 上合并。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM