在特定提交之前删除提交 [英] Remove commits before specific commit

查看:73
本文介绍了在特定提交之前删除提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以删除指定提交之前的所有提交并将其用作初始提交?

Is there a way to remove all commits before a specified commit and use that commit as the initial?

推荐答案

比方说,新的最早提交的哈希为X,我们可以临时使用"oldroot"和"newroot":

Let's say the new oldest commit's hash is X and we can use "oldroot" and "newroot" temporarily:

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!

这将创建一个与"oldroot"提交内容相同的"newroot"提交,但没有任何父母.然后,它将所有其他分支重新建立到新的根上,该根应该在所有这些分支的历史中.

That will create a 'newroot' commit with the same contents as the 'oldroot' commit, but without any parents. Then, it rebases all the other branches onto the new root, which should be in the history of all of them.

已测试并修复;稍等片刻,再精炼

tested and fixed; slightly later, refined a bit

这篇关于在特定提交之前删除提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆