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 關注
- 538 瀏覽
添加回答
舉報