How do I 'overwrite', rather than 'merge', a branch on another branch in Git?

前端 未结 13 1417
广开言路
广开言路 2020-11-27 08:51

I have two branches, email and staging. staging is the latest one and I no longer need the old changes in email branch, y

13条回答
  •  庸人自扰
    2020-11-27 09:39

    I tried @knittl's write-tree/commit-tree approach.

    branch-a: the kept branch

    branch-b: the abandoned branch

    // goto branch-a branch
    $ git checkout branch-a
    
    $ git write-tree
    6fa6989240d2fc6490f8215682a20c63dac5560a // echo tree id? I guess
    
    $ git commit-tree  -p branch-a -p branch-b 6fa6989240d2fc6490f8215682a20c63dac5560a
    
    20bc36a2b0f2537ed11328d1aedd9c3cff2e87e9 // echo new commit id
    
    $ git reset --hard 20bc36a2b0f2537ed11328d1aedd9c3cff2e87e9
    

提交回复
热议问题