我有大约20000个SVN提交记录的历史。我迁移到了Git并保留了该历史。现在我已经有26000个提交,我想将1到20000的所有提交压缩成一个。
- 最初提交:a4f5d18
- 迁移至Git:5a42d81
- HEAD:933eff
我尝试检出第20000个提交,并进行变基:
git checkout 5a42d81
git rebase squash a4f5d18
但是我得到了:
fatal: Needed a single revision
invalid upstream squash
我有大约20000个SVN提交记录的历史。我迁移到了Git并保留了该历史。现在我已经有26000个提交,我想将1到20000的所有提交压缩成一个。
我尝试检出第20000个提交,并进行变基:
git checkout 5a42d81
git rebase squash a4f5d18
fatal: Needed a single revision
invalid upstream squash
如果你想保留多少次提交记录,请在下面的命令中指定该数字
git rebase -i HEAD~6000
git rebase -i a4f5d18
git log
您可以将所有提交压缩到一个提交中。
最好将更改推送到远程,否则当您再次拉取时,将会看到所有提交。
git push -f
master: 1 -> 2 -> 3 -> .. -> 20000 -> A (第一个未迁移的提交) -> B -> C -> ..
您想要达到的目标是:
master: 1' (所有已迁移的提交) -> A' -> B' -> C' -> ..
我认为您可以采用使用git rebase HEAD~26000 (第一个提交哈希可能更容易)
并将pick
更改为squash
的方法,但这可能有些琐碎/耗时。git checkout <last migrated commit hash> -b backup-master
backup-master: 1 -> 2 -> 3 -> .. -> [20000] -> A (First non migrated commit) -> B -> C -> ..
^- you are here.
git reset --soft <first migrated commit hash>
backup-master: [1] -> 2 -> 3 -> .. -> 20000 -> A (First non migrated commit) -> B -> C -> ..
^- you are here ^- the working directory tree/index reflects this commit
reset
步骤会让你的HEAD处于分离状态。更新了答案,在初始checkout步骤中添加了一个-b <branch>
。 - Chris我在三种情况下(交互式变基、软重置、变基到)都遇到了空格的问题。Git有嫁接分支的可能性,这发展成了替换功能:
git replace -f 5a42d81 a4f5d18
git filter-branch
a4f5d18
代替HEAD~6000
。 - 1615903