简体   繁体   中英

how to rebase branch from a diverged master?

Originally, my local master branch is the same as origin/master. imagine the follows:

  1. originally

    master: a->b

    origin/master: a->b

  2. origin/master one more commit

    master: a->b

    origin/master: a->b->c

  3. master one more commit

    master: a->b->d

    origin/master: a->b->c

  4. new branch from master

    master : a->b->d

    newbranch: a->b->d->e

    origin/master: a->b->c

I tried rebasing master branch to origin/master, I expected log of new branch will be a->b->c->d->e. But instead, log of new branch is still a->b->d->e, why is that?

What I'd do:

  • Rewind local master to the last non-diverging commit b: git checkout master; git reset b git checkout master; git reset b
  • Pull remote master: git pull origin master ; this will pull in c .
  • Use git merge or git cherry-pick to put commits d and e onto master, resolve any conflicts with commit c .

Generally it is advisable to avoid working directly on a master branch. Use feature branches, do git pull --rebase on them regularly to keep in sync with master, and only merge to freshly-pulled 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