结合Git存储库的前两个提交?

结合Git存储库的前两个提交?

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

A-B-C

我想将两个提交AB组合到一个提交AB

AB-C

我试过了

git rebase -i A

这打开了我的编辑器,其中包含以下内容:

pick e97a17b Bpick asd314f C

我改成这个

squash e97a17b Bpick asd314f C

然后Git 1.6.0.4说:

Cannot 'squash' without a previous commit

有办法还是不可能?


繁花如伊
浏览 451回答 3
3回答

largeQ

使用git rebase -i --root 作为的Git 版本1.7.12。在互动变基文件,改变提交的第二线乙到压扁并保留其他线路的挑选:pick f4202da Asquash bea708e Bpick a8c6abc C这将把两个提交A和B组合成一个提交AB。

烙印99

你试过:git rebase -i A如果你继续edit而不是squash:有可能这样开始:edit e97a17b Bpick asd314f C然后运行git reset --soft HEAD^ git commit --amend git rebase --continue完成。

慕哥9229398

A是最初的提交,但现在你想B成为最初的提交。git提交是整个树,而不是差异,即使它们通常是根据它们引入的差异来描述和查看的。即使A和B以及B和C之间有多个提交,此配方仍然有效。# Go back to the last commit that we want# to form the initial commit (detach HEAD)git checkout <sha1_for_B># reset the branch pointer to the initial commit,# but leaving the index and working tree intact.git reset --soft <sha1_for_A># amend the initial tree using the tree from 'B'git commit --amend# temporarily tag this new initial commit# (or you could remember the new commit sha1 manually)git tag tmp# go back to the original branch (assume master for this example)git checkout master# Replay all the commits after B onto the new initial commitgit rebase --onto tmp <sha1_for_B># remove the temporary taggit tag -d tmp
打开App,查看更多内容
随时随地看视频慕课网APP