3

It is really difficult to understand Git rebase for beginner. I always get weird result when I rebase. I found that I can use --onto to control where I should rebase to, but how can I control the from side?

For example:

enter image description here

Let's say I am at branch 2 now, the number represent the time when the commit is done, and red color is my branch-2 commits which are not in master yet. If I want to get my branch 2 become below, what command should I use?

1) 1 -> 2 -> 8 -> 3 -> 5 -> 6 -> 7

2) 1 -> 2 -> 8 -> 5 -> 6 -> 7

In the beginning, I thought this can't be done, because my commit 3 will be gone, but I read it from Git website, this is actually valid.

enter image description here

3) 1 -> 2 -> 3 -> 5 -> 6 -> 8 -> 7

Can I do this? Basically to rebase only commit 7 on top of master?

The reason of asking these are because, auto rebase always give me headache, so I rather to be able to specify, I want to rebase from which commit onto which commit. Am I able to do so? But I can't find the from parameter.

3
  • It’s advisable to put the branch labels in the correct place. A branch points to one commit. Commented Oct 1, 2019 at 9:11
  • @evolutionxbox Hi, I don't quite get it, can you elaborate further? Commented Oct 1, 2019 at 9:43
  • If you look at the diagram from the git docs, you can see the branch names point to commits. master points to C6 for example. Commented Oct 1, 2019 at 10:22

1 Answer 1

2

First case:

git checkout branch2 git rebase máster 

Second case:

git rebase --onto master branch2~3 branch2 #rebase branch2 but skipping revision 3 

Third case:

git checkout branch2~ git cherry-pick master #pick revision 8 git cherry-pick branch2 # pick revision 7 # if you like the result git branch -f branch2 git checkout branch2 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.