我如何 git rebase 第一次提交?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22992543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I git rebase the first commit?
提问by lxs
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.
我曾经git init
创建一个新的 repo,然后进行了三个提交。现在我想 rebase 回去修改我的第一次提交,但如果我这样做git rebase -i HEAD~3
会抱怨!如果我尝试相同,HEAD~2
那么它有点工作但只让我重新排列最后两个提交。
How do I refer to the 'commit before there were any commits' or go back and insert an empty commit?
我如何引用“在有任何提交之前提交”或返回并插入一个空提交?
回答by torek
The easy way, with a recent-enough git (this has been out for a long time now so you should have this):
最简单的方法,使用足够新的 git(这已经很长时间了,所以你应该有这个):
git 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.)
正如twalberg 在评论中指出的那样,另一种简单的方法是使用git checkout --orphan
来设置进行新的根提交,您可以在其上复制旧提交。(rebase -i --root
无论如何,这就是最终在内部做的事情。)