如何在过去的两个任意提交之间注入一个提交? [英] How to inject a commit between some two arbitrary commits in the past?

查看:103
本文介绍了如何在过去的两个任意提交之间注入一个提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在本地分支上有以下提交历史记录:

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.


  1. git rebase -i<任何早期的提交> 。这会在配置的文本编辑器中显示提交列表。

  2. 查找您想要插入的提交(让我们假设它是 a1b2c3d ) 。在您的编辑器中,对于该行,将选择更改为编辑

  3. 通过关闭文本编辑器来开始重新绑定(保存您的更改)。这使您在命令提示符处输入您之前选择的提交( a1b2c3d ,就好像它刚刚提交一样。

  4. 进行修改和 git commit NOT 修改,不同于大多数 edit S)。这会在之后创建新的commit

  5. git rebase --continue 。这将重放连续的提交,并将新的提交保存在正确的位置。

  1. git rebase -i <any earlier commit>. This displays a list of commits in your configured text editor.
  2. Find the commit you want to insert after (let's assume it's a1b2c3d). In your editor, for that line, change pick to edit.
  3. 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.
  4. Make your changes and git commit (NOT amending, unlike most edits). This creates new a commit after the one you chose.
  5. 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屋!

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