如何在过去的两个任意提交之间注入一个提交? [英] How to inject a commit between some two arbitrary commits in the past?
本文介绍了如何在过去的两个任意提交之间注入一个提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我在本地分支上有以下提交历史记录:
Suppose I have the following commit history on my local-only branch:
A -- B -- C
如何在 A
和 B
?
推荐答案
p>
It's even easier than in OP's answer.
-
git rebase -i<任何早期的提交>
。这会在配置的文本编辑器中显示提交列表。 - 查找您想要插入的提交(让我们假设它是
a1b2c3d
) 。在您的编辑器中,对于该行,将选择
更改为编辑
。 - 通过关闭文本编辑器来开始重新绑定(保存您的更改)。这使您在命令提示符处输入您之前选择的提交(
a1b2c3d
),就好像它刚刚提交一样。 - 进行修改和
git commit
( NOT 修改,不同于大多数edit
S)。这会在之后创建新的commit 。 -
git rebase --continue
。这将重放连续的提交,并将新的提交保存在正确的位置。
git rebase -i <any earlier commit>
. This displays a list of commits in your configured text editor.- Find the commit you want to insert after (let's assume it's
a1b2c3d
). In your editor, for that line, changepick
toedit
. - Begin the rebase by closing your text editor (save your changes). This leaves you at a command prompt with the commit you chose earlier (
a1b2c3d
) as if it has just been committed. - Make your changes and
git commit
(NOT amending, unlike mostedit
s). This creates new a commit after the one you chose. git rebase --continue
. This replays the successive commits, leaving your new commit inserted in the correct place.
请注意,这会重写历史记录,谁试图拉。
Beware that this will rewrite history, and break anyone else who tries to pull.
这篇关于如何在过去的两个任意提交之间注入一个提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文