简体   繁体   English

如何恢复 azure devops/visual studio/git 中的合并分支

[英]How to revert a merged branch in azure devops/visual studio/git

I have merged a feature branch into develop and now need to revert this merge.我已将功能分支合并到开发中,现在需要恢复此合并。 In Azure devops when I did the pull request I couldn't see any option to squash commits (new to azure devops) and so the develop branch history looks like this..在 Azure devops 中,当我执行拉取请求时,我看不到任何压缩提交的选项(azure devops 的新选项),因此开发分支历史看起来像这样。

提交历史

So the point at which I merged the branch is 61575 but it includes all the commits on the branch.所以我合并分支的点是 61575 但它包括分支上的所有提交。 I need to revert all of the merged branch and all those commits so that the develop branch is showing as commit 0063d782.我需要还原所有合并的分支和所有这些提交,以便开发分支显示为提交 0063d782。 How would I do that please?请问我该怎么做?

Many thanks for any help非常感谢您的帮助

To "unmerge" the branch, you need to reset develop to the last commit.要“取消合并”分支,您需要将develop重置为最后一次提交。 However, by doing so you rewrite git history, so please be careful.但是,这样做会重写 git 历史记录,所以请小心。 Please make sure that no one has already pulled the merge commit you are going to remove.请确保没有人已经拉取了您要删除的合并提交。

If I understood correctly, your initial situation is:如果我理解正确,您的初始情况是:

在此处输入图像描述

In my example master points to 6146480 , which is the merge commit.在我的示例中, master 指向6146480 ,这是合并提交。 In order to remove the merge commit i need to hard reset to 82185bd , which is effectively the commit before the merge commit.为了删除合并提交,我需要硬重置为82185bd ,这实际上是合并提交之前的提交。

I can do this by executing git reset --hard HEAD~1 on the master (or develop in your specific case) branch.我可以通过在master分支(或在您的特定情况下develop )分支上执行git reset --hard HEAD~1来做到这一点。

By doing so the commit graph looks like this:通过这样做,提交图如下所示: 在此处输入图像描述

All you need to do now, is to push (you might need to force push) your changes to remote.您现在需要做的就是将您的更改推送(您可能需要强制推送)远程。

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

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