git - 如何最好地压缩旧提交

标签 git git-squash

最近离开的开发人员在几个月前的 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 为一个提交。

enter image description here


您还可以使用 --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/

相关文章:

git - 了解 merge 摘要统计数据,需要澄清

git:你的分支领先 X 次提交

git - 使用 git-svn 推送到 subversion repo 时如何保留 git 作者身份和提交日期?

Git squash 更改被远程存储库拒绝

git - 如何重置 rebase Squash ?

git - 如何将多个提交压缩到另一个分支?

Git 交互式 rebase 没有删除我的其他提交

git rebase squash 搞乱了分支历史记录

macos - 在 Git 存储库中切换分支时,文件系统中修改的日期不会更改

git - "branch creation"的简写是什么?