合并 Git 存储库的前两次提交? [英] Combine the first two commits of a Git repository?
问题描述
假设您有一个包含三个提交 A、B 和 C 的历史记录:
Suppose you have a history containing the three commits A, B and C:
A-B-C
我想将两个提交 A 和 B 合并为一个提交 AB:
I would like to combine the two commits A and B to one commit AB:
AB-C
我试过了
git rebase -i A
它打开了我的编辑器,内容如下:
which opens up my editor with the following contents:
pick e97a17b B
pick asd314f C
我把它改成
squash e97a17b B
pick asd314f C
然后 Git 1.6.0.4 说:
Then Git 1.6.0.4 says:
Cannot 'squash' without a previous commit
有没有办法或者这是不可能的?
Is there a way or is this just impossible?
推荐答案
使用 git rebase -i --root
从 Git 1.7.12 版开始.
Use git rebase -i --root
as of Git version 1.7.12.
在交互式 rebase 文件中,将 commit B 的第二行更改为 squash 并将其他行保留在 pick:
In the interactive rebase file, change the second line of commit B to squash and leave the other lines at pick:
pick f4202da A
squash bea708e B
pick a8c6abc C
这会将两个提交 A 和 B 合并为一个提交 AB.
This will combine the two commits A and B to one commit AB.
在这个答案中找到.
这篇关于合并 Git 存储库的前两次提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!