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

后端 未结 5 920
刺人心
刺人心 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条回答
  •  甜味超标
    2020-12-13 05:21

    Inspired by this answer, I came up with this:

    git replace -g HEAD HEAD^2 HEAD^1 && 
    git commit --amend && 
    git replace -d HEAD@{1}
    

    The first commands switches the two parents in something called a replacement ref, but only stores it locally, and people have called it a hack.

    The second command creates a new commit.

    The third command deletes the older replacement ref, so it doesn't mess up the other commits depending on that commit.

提交回复
热议问题