git rebase interactive: squash merge commits together

后端 未结 4 1127
灰色年华
灰色年华 2020-12-12 13:53

I wanted to have a simple solution to squash two merge commits together during an interactive rebase.

My repository looks like:

   X --- Y ---------          


        
4条回答
  •  旧时难觅i
    2020-12-12 14:35

    This is an old topic, but I just ran across it while looking for similar information.

    A trick similar to the one described in Subtree octopus merge is a really good solution to this type of problem:

    git checkout my-feature
    git reset --soft Y
    git rev-parse f > .git/MERGE_HEAD
    git commit
    

    That will take the index as it exists at the tip of my-feature, and use it to create a new commit off of Y, with 'f' as a second parent. The result is the same as if you'd never performed M1, but gone straight to performing M2.

提交回复
热议问题