合并到 GIT 后压缩分支的提交

Aks*_*hay 5 git github squash git-commit

您好,我有一个稳定的分支,其中包含其他分支的合并提交。结构如下:

提交历史:

Commit 1 - Branch 1 commit 1 ------------- Hash Code 1
Commit 2 - Branch 2 commit 1 ------------- Hash Code 2
Commit 3 - Branch 2 commit 2 ------------- Hash Code 3
Commit 4 - Branch 2 commit 3 ------------- Hash Code 4
Commit 5 - Branch 3 commit 1 ------------- Hash Code 5
Run Code Online (Sandbox Code Playgroud)

分支 1,2,3 被删除并已合并到 stable 中。有什么方法可以在提交历史记录中压缩提交 3 和提交 4。

期望的结果:

Commit 1 - Branch 1 commit 1 ------------- Hash Code 1
Commit 2 - Branch 2 commit 1 ------------- Hash Code 2
Commit 5 - Branch 3 commit 1 ------------- Hash Code 5
Run Code Online (Sandbox Code Playgroud)

当我执行 git rebase -i 时,它会在 rebase 中给出 noop scrren 。在此输入图像描述

Cha*_*Rai 6

您可以执行 git rebase -i 来执行交互式变基。

git rebase -i HEAD~4
Run Code Online (Sandbox Code Playgroud)

改变

pick  commit 1
pick  commit 2
pick  commit 3
pick  commit 1
Run Code Online (Sandbox Code Playgroud)

进入这个

pick  commit 1
s     commit 2
s     commit 3
pick  commit 1
Run Code Online (Sandbox Code Playgroud)

保存更改并执行git push -f