git 在 Bitbucket 上恢复合并的拉取请求
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38302119/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Revert a merged pull request on Bitbucket
提问by Jordi
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?
到目前为止,我一直想看看那边,我能够硬重置目标分支……但是,origin
存储库中的拉取请求怎么样?
I'm using Bitbucket and I've created the pull request from SourceTree (opening the Bitbucket page).
我正在使用 Bitbucket 并且我已经从 SourceTree 创建了拉取请求(打开 Bitbucket 页面)。
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
.
我正在处理三个分支:master
,dev
和create-alias
. create-alias
是从dev
和dev
从master
: 设置的master -> dev -> create-alias
。问题是我提出了一个拉取请求create-alias
,我确实将它合并到master
而不是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
.
我现在在create-alias
分支上工作。最后一次提交create-alias
是6ee20f9
,合并提交master
是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:
到目前为止,我已经能够弄清楚:
- checkout on
master
. - revert -m 1
6ee20f9
. - push.
- checkout on
create-alias
and going on working.
- 结帐
master
。 - 恢复 -m 1
6ee20f9
。 - 推。
- 结帐
create-alias
并继续工作。
Isn't it?
不是吗?
回答by Will
Unfortunately, there is no "Revert Pull Request" feature on Bitbucket as of this writing, but a feature request exists for it.
不幸的是,在撰写本文时,Bitbucket 上没有“恢复拉取请求”功能,但存在一个功能请求。
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.
因此,您必须在 Git 中恢复合并。首先,找到合并提交的 SHA 哈希值。
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:
在 SourceTree 中,首先检出有问题的分支,然后Pull。在日志窗口中找到合并提交,然后右键单击它,然后单击Copy SHA-1 to Clipboard...。然后转到Actions --> Open in Terminal。终端打开后,输入:
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.
回答by oknate
Bitbucket has a "revert" button on Pull Requests now.
Bitbucket 现在在 Pull Requests 上有一个“revert”按钮。
Note it doesn't automatically update the branch the original PR was merged into it. It creates a new branch with a commit that reverts the PR:
请注意,它不会自动更新原始 PR 合并到其中的分支。它创建一个带有恢复 PR 的提交的新分支:
You then can create a PR from this branch and merge it.
然后你可以从这个分支创建一个 PR 并合并它。