合并 Git 存储库的前两次提交? [英] Combine the first two commits of a Git repository?

查看:21
本文介绍了合并 Git 存储库的前两次提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设您有一个包含三个提交 A、BC 的历史记录:

Suppose you have a history containing the three commits A, B and C:

A-B-C

我想将两个提交 AB 合并为一个提交 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

这会将两个提交 AB 合并为一个提交 AB.

This will combine the two commits A and B to one commit AB.

这个答案中找到.

这篇关于合并 Git 存储库的前两次提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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