git interactive rebase squash into next commit

后端 未结 4 1097
一个人的身影
一个人的身影 2021-02-13 21:59

In Git I can use an interactive rebase to re-write history, this is great because in my feature branch I made a ton of commits with partially working code as I explored differen

4条回答
  •  独厮守ぢ
    2021-02-13 22:24

    You either need to also reorder the commits so the to-be-kept commit comes before the to-be-squashed commits if this is feasible.

    If this is not feasible, because you then would get conflicts you don't want to resolve, just make it

    1. pick
    2. squash
    3. squash
    4. pick 
    5. pick
    6. squash
    7. squash
    

    When the squashes are done, you can edit the commit message to contain the message you like the final commits to have. Easy as pie. :-)

    You might even be able to do

    1. pick
    2. fixup
    3. squash
    4. pick 
    5. pick
    6. fixup
    7. squash
    

    Then I think there should only once the commit message editor being fired up, as with fixup the previous commit message is simply taken without launching the editor.

    On squash when the commit message editor fires, you also get both commit messages, the one from the to-be-squashed-into and the to-be-squashed commit, so you then can simply delete the commit message you don't want to keep.

提交回复
热议问题