what's is the different between git rebase and git meger.
1. build a environment of the test
first of all . create the branch like below
D:\gitTest\Download4Http>git branch
Bensonhe-dev
change-branch
dev
master
merge-branch
* rebase-branch
then change something on change-branch and commit it as node “changeA” .
and change it again and commit as node “changB”
the same way for the merge-branch and rebase-branch
D:\gitTest\Download4Http>git branch D:\gitTest\Download4Http>git checkout change-branch D:\gitTest\Download4Http>git commit -a -m "changeA" D:\gitTest\Download4Http>git commit -a -m "changeB" D:\gitTest\Download4Http>git checkout merge-branch D:\gitTest\Download4Http>git commit -a -m"mergeA" D:\gitTest\Download4Http>git commit -a -m"mergeB" D:\gitTest\Download4Http>git checkout rebase-branch D:\gitTest\Download4Http>git commit -a -m "rebaseA" D:\gitTest\Download4Http>git commit -a -m "rebaseB" |
after the finish. the node tree should be like this
2. Test for it
change branch on the rebase-branch
use the command git rebase change-branch. and show the log
you can find have 4 commit nodes. the branch tree like this
use the command git merge change-branch. and show the log
you can find the git will create a new commit node . total have 5 commit nodes. the branch tree like this
3. when should I use git rebase? when should I use git merge?
below show the how to fix the 2 conflict when you merge different branch
D:\gitTest\Download4Http>git branch D:\gitTest\Download4Http>git checkout change-branch D:\gitTest\Download4Http>git commit -a -m "changeConflictA" D:\gitTest\Download4Http>git commit -a -m "changeConflictB" D:\gitTest\Download4Http>git checkout merge-branch D:\gitTest\Download4Http>git commit -a -m "mergeConflictA" D:\gitTest\Download4Http>git commit -a -m "mergeConflictB" D:\gitTest\Download4Http>git merge change-change D:\gitTest\Download4Http>git merge change-branch D:\gitTest\Download4Http>git commit -a -m "fix the merge Conflict" D:\gitTest\Download4Http>git merge change-branch |
below show the how to fix the 2 conflict when you rebase different branch
the rebase if have conflict is default with merge.
use reabase ,the git will apply commit node one by one.like this
if the git find conflict . it will skip branch (no branch) for your merge the changes
if you merge one by yourself . use git add to add index for the changes.and use git rebase – –continue to continue rebase
the git will aplly next node .
until you finish the all conflict
the different from git merge. the git merge will apply all the changes by one time.
so I think if have many commit nodes . you had better use git merge.
if only few commit node .you had better use the git rebase. it can loss the commit nodes.it is better for you to manager the branch
if you have any question .you can send email to me .my email adress is qing878@gmail.com ,the skype is qing878
thanks
Benson
文章是我原创,用英文写只为了提高下英语水平,水平很烂勿喷啊,呵呵,欢迎交流,我标明啊,编者别删拉