git 如何撤消 Bitbucket 上的合并?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37036381/
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
How to undo a merge on Bitbucket?
提问by James
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.
我创建了一个现在位于 Bitbucket 存储库上的合并(到“主”分支)。长话短说:我需要撤消该合并。
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.
我知道您可以在 Github 站点本身执行此操作,但 Bitbucket 没有该功能。我不清楚如何在不造成混乱的情况下使用 Git 做到这一点。
回答by Ville
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 存储库的“概览”页面获取 SSH 或 HTTPS 格式的存储库 URL):
git clone [email protected]:my/repo.git
-or-
git clone https://[email protected]/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.
自然地,如果 repo 是共享的,并且它的其他用户已经提取了您最近的提交并在其上构建,他们将不会高兴。所以在这种情况下,一定要通知大家你在做什么。
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.
revert
,正如其他答案中提到的那样,是另一种选择;它会保留您所做的提交,但会进一步修改存储库(使用新提交),以撤消您所做的更改。是否要使用revert
取决于您是否希望提交中的信息保留在 repo 历史记录中。
For more detail on undoing changes in git, see a good tutorial page by Atlassian.
有关在 git 中撤消更改的更多详细信息,请参阅Atlassian 的一个很好的教程页面。
回答by BrunoFacca
A "Revert pull request" feature was implemented in Bitbucket in 2017.
2017 年在 Bitbucket 中实现了“恢复拉取请求”功能。
To revert a pull request:
要恢复拉取请求:
- 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.
- 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.
- 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.
- 在拉取请求中,单击右上角的 Revert 按钮。(可选)在 Revert pull request 对话框中,更改您将要创建的新分支的分支名称。
- 单击还原按钮。单击“还原”后,Bitbucket 将创建新分支。即使您取消拉取请求,恢复分支仍保留在存储库中。
- Create a pull request 页面打开,revert 分支作为源。添加审阅者并进行其他更改后,单击创建。
Source: the docs.
来源:文档。
回答by Uzbekjon
I would suggest doing a revert
instead, since you are reverting a public repo.
我建议做一个revert
,因为你正在恢复一个公共回购。
git revert HEAD
git push -f origin
回答by endikap100
to undo the changes of a commit:
git revert <commit id>
撤消提交的更改:
git revert <commit id>