git - 交互式 rebase 时将更改移动到不同的提交

标签 git git-rebase

在清理(即主要压缩)一些更大功能的历史记录时,我经常遇到以下情况:

Commit A:
  - change A.1
  - change A.2
  - change A.3

// EDIT: maybe some more commits

Commit B:
  - change B.1
  - change B.2
  - change B.3

假设现在我想移动 change B.1 以使用交互式 rebase 提交 A。到目前为止,我找到的唯一方法是:

  1. 开始rebase -i
  2. 编辑提交 B
  3. 在 tmp 提交和提交 B 中拆分提交 B(reset HEAD^ 然后 add -p)
  4. 开始rebase -i
  5. 修复提交 A 中的 tmp 提交

这需要两次 rebase 并且非常麻烦。另外,我必须在拆分时重写提交 B 的提交消息。

有没有更好/更有效的方法来实现这一点?

最佳答案

可能不是一个显着的改进,但是

  1. git rebase -i A^
  2. git cherry-pick --no-commit B
  3. git add -p
  4. git commit --amend
  5. git reset --hard
  6. git rebase --continue

将是另一种选择。

关于git - 交互式 rebase 时将更改移动到不同的提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20677725/

相关文章:

macos - 'atal : Reference has invalid format: 'refs/Icon

git - Git 中有多个根节点是否有任何问题?

git - 如何自动化master分支的git版本发布?

git - 压缩本地提交后推送到远程分支失败

git - 为什么git rebase总是冲突?

git - 在 Pull 请求后 rebase

git维护同一个项目的两个版本,每个版本都有不同的用户

git 命令检索最新的 git 提交消息

git 从 pull 请求中删除提交

git - merge 和 rebase 如何工作?