Git: how to use rebase with theirs strategy

后端 未结 2 1705
旧巷少年郎
旧巷少年郎 2021-01-22 09:01

Basically, I just want to (re)set the parent (let\'s say to commit A) of a specific commit (commit B) which is the root commit of some branch x

相关标签:
2条回答
  • 2021-01-22 09:41

    I'm not entirely sure I understand your question, but if your aim is to go from this:

    o C (X)
    |
    o B
    
    o A
    

    to this:

    o C' (X)
    |
    o B'
    |
    o A
    

    then git replace --graft B A should do what you want.

    N.B. B and B' have the same filetrees as each other, but different commit hashes because their parent commits are different. Likewise C and C'.

    Why this has to be done via git replace --graft rather than git rebase -s theirs, I don't know. Presumably it is for hysterical raisins.

    Also see: this answer to How do git grafts and replace differ? (Are grafts now deprecated?).

    0 讨论(0)
  • 2021-01-22 09:48

    rebase isn't designed for what you want to do. The other poster was correct; what you want to do is set up a graft to attach B to A, then run git filter-branch to bake it into the commits. An example of this exact use case can be found in the git filter-branch manpage.

    0 讨论(0)
提交回复
热议问题