为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

Git
繁花如伊 2019-08-15 14:04:47
结合Git存储库的前两个提交?假设您有一个包含三个提交A,B和C的历史记录:A-B-C我想将两个提交A和B组合到一个提交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有办法还是不可能?
查看完整描述

3 回答

?
largeQ

TA贡献2039条经验 获得超7个赞

使用git rebase -i --root 作为的Git 版本1.7.12

在互动变基文件,改变提交的第二线压扁并保留其他线路的挑选

pick f4202da Asquash bea708e Bpick a8c6abc C

这将把两个提交AB组合成一个提交AB


查看完整回答
反对 回复 2019-08-15
?
烙印99

TA贡献1829条经验 获得超13个赞

你试过:

git rebase -i A

如果你继续edit而不是squash:有可能这样开始:

edit e97a17b Bpick asd314f C

然后运行

git reset --soft HEAD^
git commit --amend
git rebase --continue

完成。


查看完整回答
反对 回复 2019-08-15
?
慕哥9229398

TA贡献1877条经验 获得超6个赞

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 commit

git rebase --onto tmp <sha1_for_B>


# remove the temporary tag

git tag -d tmp


查看完整回答
反对 回复 2019-08-15
  • 3 回答
  • 0 关注
  • 440 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信