如何删除不需要的git分支“循环"? [英] How to remove an unwanted git branch "loop"

查看:101
本文介绍了如何删除不需要的git分支“循环"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我管理"的分支上进行交互式基础调整和合并时,创建以下分支循环:

While interactive rebasing and merging on a branch I "managed" to create the following branch loop:

---a-----------g--h----m--n---
    \--b--c--d--e--f--/

  • b,c,d,e和f提交是在调试期间完成的.
  • g和h提交是由于交互式重新基准化
  • m提交导致合并...
  • 我想保留a-g-h-m-n的历史记录,并摆脱-b-c-d-e-f的历史记录.我该怎么办?
    • The b, c, d, e and f commits were done during debug.
    • The g and h commits resulted from interactive rebasing
    • The m commit resulted a merge ...
    • I would like to keep the a-g-h-m-n history and get rid of the -b-c-d-e-f history. How could I do it?
    • 让我澄清一下,我的目标是消除 -bcdef-历史记录行,保持 m 合并并以单行 -aghmn结尾-历史.

      Let me clarify, my goal here is to eliminate the -b-c-d-e-f- history line, keep the m merge and end up with the single line -a-g-h-m-n- history.

      推荐答案

      我想保留a-g-h-m-n的历史记录,并摆脱-b-c-d-e-f的历史记录. ...历史记录的b-c-d-e-f部分相当于g-h,我想删除b-c-d-e-f一个我该怎么做?

      ---a-----------g--h----m--n---
          \--b--c--d--e--f--/
      

      我不完全相信这是一个好主意.如果a-g-h-m和a-b-c-d-e-f-m等效,则合并不会发生.您可以使用git diff h f查看差异并做出决定.

      I'm not fully convinced this is a good idea. If a-g-h-m and a-b-c-d-e-f-m were equivalent the merge would not have happened. You can look at the differences with git diff h f and decide.

      但这是操作方法.

      您需要消除m合并.您想要这样的东西:

      You need to eliminate the m merge. You want something like this:

      ---a-----------g--h----n
          \--b--c--d--e--f
      

      为此,您需要将母版移回h,然后将n嫁接到h上.分支头(master是分支头)与git reset --hard一起移动.用git cherry-pick进行嫁接.

      To do that you need to move master back to h and then graft n onto h. Branch heads (master is a branch head) are moved with git reset --hard. Grafting is done with git cherry-pick.

      • git checkout master
      • git reset --hard hmaster移回h.
      • git cherry-pick nn重新修补到h.
      • git checkout master
      • git reset --hard h moves master back to h.
      • git cherry-pick n repatches n onto h.

      请注意,这将导致n具有新的提交ID.如果按下n,这将对其他贡献者造成问题.拥有n的任何人在下次尝试推或拉时都会出错,并且需要git pull --force.

      Note that this will result in n having a new commit id. This will cause problems for other contributors if n was pushed. Anyone who has n will get an error next time they try to push or pull and will need to git pull --force.

      这篇关于如何删除不需要的git分支“循环"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆