How to modify a specified commit?

后端 未结 16 1182
清酒与你
清酒与你 2020-11-22 01:53

I usually submit a list of commits for review. If I have the following commits:

  1. HEAD
  2. Commit3
  3. Commit2
16条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-22 02:27

    I solved this,

    1) by creating new commit with changes i want..

    r8gs4r commit 0
    

    2) i know which commit i need to merge with it. which is commit 3.

    so, git rebase -i HEAD~4 # 4 represents recent 4 commit (here commit 3 is in 4th place)

    3) in interactive rebase recent commit will located at bottom. it will looks alike,

    pick q6ade6 commit 3
    pick vr43de commit 2
    pick ac123d commit 1
    pick r8gs4r commit 0
    

    4) here we need to rearrange commit if you want to merge with specific one. it should be like,

    parent
    |_child
    
    pick q6ade6 commit 3
    f r8gs4r commit 0
    pick vr43de commit 2
    pick ac123d commit 1
    

    after rearrange you need to replace p pick with f (fixup will merge without commit message) or s (squash merge with commit message can change in run time)

    and then save your tree.

    now merge done with existing commit.

    Note: Its not preferable method unless you're maintain on your own. if you have big team size its not a acceptable method to rewrite git tree will end up in conflicts which you know other wont. if you want to maintain you tree clean with less commits can try this and if its small team otherwise its not preferable.....

提交回复
热议问题