以编程方式交换最后两个提交 [英] Programmatically swap last two commits
问题描述
我知道如何使用 git rebase
以交互方式交换后两个提交( git rebase -i HEAD〜2
, ddjp:x
在Vim中),但是我想用一个包装脚本以编程的方式来完成它,因为这是我经常做的事。
具体来说,我想从
A --- B- --C --- D HEAD
到
A --- B --- D --- C HEAD
以完全脚本化的方式。理想情况下,如果交换失败,它应该允许我以交互方式修复它,或者放弃并告诉我手动执行。
git tag old
git reset --hard HEAD〜2
git cherry-pick old
git cherry-pick old〜1
git tag -d old
首先,将 git cherry-pick
提交另一个订单,并删除旧的
标签。
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 programmatically with a wrapper script since it's something I end up doing relatively often.
To be more concrete, I want to rewrite history from
A---B---C---D HEAD
to
A---B---D---C HEAD
in an entirely scripted manner. Ideally, if the swap fails, it should either allow me to fix it interactively or just give up and tell me to do it manually.
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.
这篇关于以编程方式交换最后两个提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!