Wal*_*ndt 25
假设新的最旧提交的哈希是X,我们可以暂时使用"oldroot"和"newroot":
git checkout -b oldroot X
TREE=`git write-tree`
COMMIT=`echo "Killed history" | git commit-tree "$TREE"`
git checkout -b newroot "$COMMIT"
git rebase --onto newroot oldroot master
# repeat for other branches than master that should use the new initial commit
git checkout master
git branch -D oldroot
git branch -D newroot
git gc # WARNING: if everything's done right, this will actually delete your history from the repo!
Run Code Online (Sandbox Code Playgroud)
这将创建一个'newroot'提交,其内容与'oldroot'提交相同,但没有任何父母.然后,它将所有其他分支重新绑定到新根,这应该在所有分支的历史中.
编辑:测试和修复; 稍晚,精炼了一下