I'm working on branch C which is based on branch B, then branch A:
A---B---C
Is there any commands that can make branch C directly based on branch A like this:
A---B \\ --C
I have tried git rebase A
but it does not work.
git rebase --onto A B C
Explanation:
In rebase command, you can define:
and the command is
git rebase --onto TargetBranchToRebaseTo UpstreamBranch BranchToRebase
In fact you can almost an exact example in git help rebase
Here's what I would do:
git checkout C
git checkout -b rebaseTemp
git rebase -i A
In the interactive rebase, delete all of the commits that correspond to branch B, but aren't a part of branch C (ie the commits that are shared between the two). Complete the rebase, then you will have a new branch (rebaseTemp) that contains what I think you want. You can then merge A into rebaseTemp (which will result in a fast-forward merge).
A branch visualization tool (ie gitk
) is really useful for this scenario, so you can see what commits are shared.
Git has a builtin option to rebase
that does just that:
git checkout C
git rebase --onto A B
This rebases all of the commits after B up to C such that they start on A instead of B.
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.