问题
I have this:
master
| foo
| |
v v bar
A---B---C---D |
\ v
\---E---F---G
I want this:
master
| foo
| |
v v bar
A---B---C---D |
\ v
\---E---F---G
so I think I need to do:
git checkout bar
git rebase master
but Git thinks otherwise:
Current branch bar is up-to-date.
and leaves everything as it is.
What do I need to run to make Git do what I want?
回答1:
The version of git rebase
that you are doing, takes all of the commits on the branch bar
which are not already on master
and writes them onto master
. This is commits D
through F
, which isn't what you want because it doesn't skip commit D
. One solution is to use the --onto
flag:
git checkout bar
git rebase --onto master foo
This version of rebase will take all of the commits on the branch bar
but not on branch foo
and rewrite them onto master
. This will result in exactly the history for bar
that you want.
回答2:
Commit D
is included on the branch bar
. One option is to do an interactive rebase and delete commit D
from branch bar
.
git checkout bar
git rebase -i master
- In text editor delete line of commit
D
- Save and close
As long as you have a tag or branch on commit D
(or that includes commit D
) (for example foo
) you should not lose it. Also remember that if the commits after D
depend on changes in D
you will get conflicts.
来源:https://stackoverflow.com/questions/52192249/git-rebase-not-updating-branch