3 回答
TA贡献1829条经验 获得超13个赞
你试过:
git rebase -i A
如果你继续edit
而不是squash
:有可能这样开始:
edit e97a17b Bpick asd314f C
然后运行
git reset --soft HEAD^ git commit --amend git rebase --continue
完成。
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
- 3 回答
- 0 关注
- 493 浏览
添加回答
举报