我分叉了一个repo,工作了一段时间,大约有10次提交(10c),然后我从上游(m1)合并,然后工作了一段时间,有3次提交(3c)。
我现在试图重新定位,而3c是可以的,当我超越m1重新定位/压缩消息时,它要求我再次合并-为什么?
而不是合并10c:
X--x--x--M (10c) --x--x--x (3c, master)
/ /
u--u--u--u--u (upstream/master)
最好是在upstream/master之上重新设置 10c。
考虑到当前的情况,你有10次提交(从X到M,不包括合并提交),然后3次提交,你可以这样做:
# let's mark the current master
git checkout master
git branch tmp
# let's reset master to just before the merge commit
# make sure you don't have any work in progress
git stash
git reset --hard M^1
X--x--x (master) --M (10c) --x--x--x (3c, tmp)
/ /
u--u--u--u------------u (upstream/master)
# let's rebase those 10 commits (from X) on top of upstream master
git rebase upstream/master
X--x--x--M (10c) --x--x--x (3c, tmp)
/ /
u--u--u--u--u (upstream/master) --X'--x'--x' (master)
# Finally, rebase tmp
git checkout tmp
git rebase --onto master M tmp
git merge master
X--x--x--M (10c) --x--x--x (3c)
/ /
u--u--u--u--u (upstream/master) --X'--x'--x'--x'--x'--x' (tmp,master)