我如何git rebase第一个提交? [英] How do I git rebase the first commit?
问题描述
我用git init
创建了一个新的仓库,然后进行了3次提交.现在,我想重新建立基础并修改我的第一次提交,但是如果我执行git rebase -i HEAD~3
,它会抱怨!如果我在HEAD~2
上尝试相同的操作,那还是可以的,但是只能让我重新排列最后两个提交.
I used git init
to create a fresh repo, then made three commits. Now I want to rebase to go back and amend my first commit, but if I do git rebase -i HEAD~3
it complains! If I try the same with HEAD~2
then it kinda works but only lets me rearrange the last two commits.
我如何指代有任何提交之前的提交"或返回并插入一个空的提交?
How do I refer to the 'commit before there were any commits' or go back and insert an empty commit?
推荐答案
使用最近足够的git的简单方法(这种方法已经存在很长时间了,所以您应该使用它):
The easy way, with a recent-enough git (this has been out for a long time now so you should have this):
git rebase -i --root
另一种简单的方法,如 twalberg在评论中指出的,是使用git checkout --orphan
进行设置一个新的根提交,您可以在其上面复制旧的提交. (这是rebase -i --root
最终还是在内部完成的工作.)
The other easy way, as twalberg noted in a comment, is to use git checkout --orphan
to set up to make a new root commit, which you can copy the old commits on top of. (This is what rebase -i --root
ends up doing internally anyway.)
这篇关于我如何git rebase第一个提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!