简体   繁体   English

rebase合并提交后如何恢复合并?

[英]How to revert the merge after rebase merged commit?

I merged the branch from test to master.我将分支从 test 合并到 master。 Then i need to revert it but i can't revert merged commit so i do rebase.然后我需要恢复它,但我无法恢复合并的提交,所以我做 rebase。 But after the rebase branch still show as a merged i can't see branch difference.但是在 rebase 分支仍然显示为合并后,我看不到分支差异。 What is the possible way to fix this?解决此问题的可能方法是什么?

If you want to undo the merge, and if rewriting history is ok in your situation:如果您想撤消合并,并且在您的情况下可以重写历史记录:

  1. Make sure you have a backup of your repo (just in case).确保你有你的 repo 的备份(以防万一)。 Just copy the whole directory.只需复制整个目录。

  2. Find the commit hash on the master branch for the commit just before the merge.在合并之前的提交的主分支上找到提交 hash。 Let's call it xyz .我们称之为xyz

    This git log command makes it easy:这个 git 日志命令很容易:

     git log --graph --all --pretty="%C(dim yellow)%h %C(dim cyan)%cd %C(auto)%d%C(reset) %s"

  3. Do this: git branch -f master <xyz> .这样做: git branch -f master <xyz>

  4. Make sure everything is as you want it:确保一切如你所愿:

    • look at the updated history (eg using my git log command above).查看更新的历史记录(例如,使用我上面的 git 日志命令)。 It should no longer show a merge.它不应再显示合并。
    • checkout master, and make sure it is how it should be.结帐大师,并确保它应该是这样的。 You can also run git log --oneline from this context for one final verification.您还可以从此上下文中运行git log --oneline进行最终验证。
  5. If you had previously pushed the merge master to a remote, you can overwrite that with git push -f (adding whatever other params you used in the push command before).如果您之前已将合并主服务器推送到远程,则可以使用git push -f覆盖它(添加您之前在推送命令中使用的任何其他参数)。

    ⚠️ BE AWARE: you are rewriting history and this may impact other users who have already started doing work on the merged master. ⚠️ 请注意:您正在重写历史记录,这可能会影响已经开始在合并后的 master 上工作的其他用户。

  6. When you are sure everything is as they should be, and nothing wanted has been lost, delete your backup copy.当您确定一切正常,并且没有丢失任何想要的东西时,请删除您的备份副本。 But it doesn't hurt to keep it around for a couple of weeks until you are sure.但是在您确定之前将其保留几个星期并没有什么坏处。

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

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