How do I swap the order of two parents of a Git commit?

后端 未结 5 906
刺人心
刺人心 2020-12-13 04:38

A merge commit is a commit with at least two parents. These parents are in specific order.

If I\'m currently on the branch master, and I merge in the br

5条回答
  •  Happy的楠姐
    2020-12-13 05:15

    Actualy, there's a really cool command I learned recently that will do exactly what you want:

    git commit-tree -p HEAD^2 -p HEAD^1 -m "Commit message" "HEAD^{tree}" 
    

    This will create a new commit based on what is currently HEAD, but pretend that it's parents were HEAD^2,HEAD^1 (note this is the reversed order).

    git-commit-tree prints the new revision as output, so you might combine it with a git-reset-hard:

    git reset --hard $(git commit-tree -p HEAD^2 -p HEAD^1 -m "New commit message" "HEAD^{tree}")
    

提交回复
热议问题