简体   繁体   中英

git merge upstream and the rebase further down causes me to merge again

I forked out a repo and worked for a while with some 10 commits (10c), then I merged from upstream (m1) and then worked for a while and had 3 commits (3c).

Iam trying to rebase now, while 3c is ok, when I go beyond m1 to rebase/squash messages, It is asking me to merge again - why?

Instead of having merged 10c:

     X--x--x--M (10c) --x--x--x (3c, master)
    /        /
u--u--u--u--u (upstream/master)

It would have been best to rebase 10c on top of upstream/master.

Considering the current situation, where you have 10 commits (from X to M, excluding the merge commit), then 3 commits, you could do:

# 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM