以编程方式交换最后两个提交 [英] Programmatically swap last two commits

查看:123
本文介绍了以编程方式交换最后两个提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何使用 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

首先,将 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆