当存在不属于当前PR的提交时,如何压缩提交

时间:2019-05-07 21:36:45

标签: git

如果我做git rebase -i HEAD~5,我会得到

pick <hash1> CURR_PR
pick <hash2> PREV_PR_I_WORKED_ON
pick <hash3> WIP: another commit I want to squash in to CURR_PR
pick <hash4> WIP: yet another commit I want to squash in to CURR_PR
pick <hash5> WIP: and finally one more commit I want to squash in to CURR_PR

通常,我只是将pick下的所有CURR_PR替换为s,然后进行更改然后清理提交消息。但是,由于某种原因,我已经用<hash2>提交了,所以我不想挤进去。

如何将hash3, hash4, hash5的提交压缩为hash1的提交?

1 个答案:

答案 0 :(得分:1)

假设您要保留提交<hash2>的更改,只需将<hash2>提交的行移到您想要的位置:

pick <hash1> CURR_PR
squash <hash3> WIP: another commit I want to squash in to CURR_PR
squash <hash4> WIP: yet another commit I want to squash in to CURR_PR
squash <hash5> WIP: and finally one more commit I want to squash in to CURR_PR
pick <hash2> PREV_PR_I_WORKED_ON

在这种情况下,您将拥有一个压缩<hash1><hash3>hash4<hash5>的提交,以及一个包含<hash2>变化的提交< / p>

如果您要删除提交<squash2>的更改,只需删除该行即可。