Tuesday, August 27, 2013

git : rebate a branch onto a commit

First understand what is difference between merge and rebase . Let us see how to rebase a branch to a particular commit.

I have committed three changes. When I am in alphabranch, I can see three commits 83fc543 ,  0e6b2fe , 26e6ec2 

$  git checkout alphabranch
Switched to branch 'alphabranch'

$  git log --graph --decorate --oneline -n5
* 83fc543 (HEAD, alphabranch) third commit on third_file.txt
* 0e6b2fe (betabranch) second commit for second_file.txt
* 26e6ec2 first commit for first_file.txt
* b3a6800 (gerrit/master, gerrit/HEAD) your college submitted some patch
* 3d1bb52 (master) boss has submitted fix


Let us create a  gamabranch branch from *master*.  You will not have above three commit in new gamabranch . This branch will be at master HEAD commit 3d1bb52 

$  git checkout -b gamabranch master        ## From master
Switched to branch 'gamabranch'

$  git log --graph --decorate --oneline -n5
* 3d1bb52 (HEAD, master, gamabranch) boss has submitted fix
* bb7ebab change for system foo config file
* 244c06f patch for video diplay driver


Now rebase gamabranch to commit 0e6b2fe. It will rebase new branch with changes commited in 0e6b2fe and plus its in-line predecessors commits.

$  git rebase 0e6b2fe 
First, rewinding head to replay your work on top of it...
Fast-forwarded gamabranch hto 0e6b2fe.

$  git log --graph --decorate --oneline -n5
0e6b2fe (HEAD, gamabranch, betabranch) second commit for second_file.txt
26e6ec2 first commit for first_file.txt
* b3a6800 (gerrit/master, gerrit/HEAD) your colleage submitted some patch
* 3d1bb52 (master) boss has submitted fix
* bb7ebab change for system foo config file

No comments:

Post a Comment