最近离开的开发人员在几个月前的 repo 协议(protocol)中留下了大量提交,就像“更新”一样。理想情况下,我想将它们压缩成一个提交,但我只对最近的提交这样做过。
我将如何处理以下提交(假设 2 个月前的提交意味着有数百个这样的提交)?
....从 2 个月前
aabbcc updated
aabbdd updated
aabbee updated
aabbff updated
不需要/不需要任何花哨的东西,只是一个简单的解决方案。这些提交尚未公开共享(除了今天与我共享),所以没有扰乱其他人的提交历史的问题。
最佳答案
要执行 git squash,请按照以下步骤操作:
// X is the number of commits you wish to squash
git rebase -i HEAD~X
压缩提交后 - 选择 s
进行压缩 = 它将所有提交 merge 为一个提交。
您还可以使用 --root 标志以备不时之需
尝试:git rebase -i --root
--根
Rebase all commits reachable from <branch>, instead of limiting them with
an <upstream>.
This allows you to rebase the root commit(s) on a branch.
When used with --onto, it will skip changes already contained in `<newbase>`
(instead of `<upstream>`) whereas without --onto it will operate on every
change. When used together with both --onto and --preserve-merges, all root
commits will be rewritten to have `<newbase>` as parent instead.`
关于git - 如何最好地压缩旧提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34733338/