Programmatically swap last two commits

后端 未结 3 676
时光说笑
时光说笑 2020-12-25 12:46

I know how to swap the last two commits using git rebase interactively (git rebase -i HEAD~2, ddjp:x in Vim), but I\'d like to do it p

3条回答
  •  盖世英雄少女心
    2020-12-25 12:54

    This should do it:

    git tag old
    git reset --hard HEAD~2
    git cherry-pick old
    git cherry-pick old~1
    git tag -d old
    

    First, you tag the place where you are as old, then go back two commits, git cherry-pick the commits in the other order, and delete the old tag.

提交回复
热议问题