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

 

image

 

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
  Bensonhe-dev
  change-branch
  dev
  master
  merge-branch
* rebase-branch

D:\gitTest\Download4Http>git checkout change-branch
Switched to branch 'change-branch'

D:\gitTest\Download4Http>git commit -a -m "changeA"
[change-branch 0672bb4] changeA
1 file changed, 1 insertion(+), 1 deletion(-)

D:\gitTest\Download4Http>git commit -a -m "changeB"
[change-branch 97d5ac4] changeB
1 file changed, 1 insertion(+), 1 deletion(-)

D:\gitTest\Download4Http>git checkout merge-branch
Switched to branch 'merge-branch'

D:\gitTest\Download4Http>git commit -a -m"mergeA"
[merge-branch d29ddb1] mergeA
1 file changed, 2 insertions(+), 1 deletion(-)

D:\gitTest\Download4Http>git commit -a -m"mergeB"
[merge-branch 76d4732] mergeB
1 file changed, 1 insertion(+), 1 deletion(-)

D:\gitTest\Download4Http>git checkout rebase-branch
Switched to branch 'rebase-branch'

D:\gitTest\Download4Http>git commit -a -m "rebaseA"
[rebase-branch c213fec] rebaseA
1 file changed, 2 insertions(+), 1 deletion(-)

D:\gitTest\Download4Http>git commit -a -m "rebaseB"
[rebase-branch 6cd92c2] rebaseB
1 file changed, 1 insertion(+), 1 deletion(-)

after the finish. the node tree should be like  this

image

2. Test for it

change branch on the rebase-branch

use the command git rebase change-branch. and show the log

image

you can find have 4 commit nodes. the branch tree like this

image

 

use the command git merge change-branch. and show the log

image

you can find the git will create a new commit node . total have 5 commit nodes. the branch tree like this

image

 

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
  Bensonhe-dev
  change-branch
  dev
  master
* merge-branch
  rebase-branch

D:\gitTest\Download4Http>git checkout change-branch
Switched to branch 'change-branch'

D:\gitTest\Download4Http>git commit -a -m "changeConflictA"
[change-branch d3b8845] changeConflictA
1 file changed, 1 insertion(+), 1 deletion(-)

D:\gitTest\Download4Http>git commit -a -m "changeConflictB"
[change-branch 76b70ba] changeConflictB
1 file changed, 1 insertion(+), 1 deletion(-)

D:\gitTest\Download4Http>git checkout merge-branch
Switched to branch 'merge-branch'

D:\gitTest\Download4Http>git commit -a -m "mergeConflictA"
[merge-branch 4ad0e13] mergeConflictA
1 file changed, 1 insertion(+), 1 deletion(-)

D:\gitTest\Download4Http>git commit -a -m "mergeConflictB"
[merge-branch 5c1a613] mergeConflictB
1 file changed, 1 insertion(+), 1 deletion(-)

D:\gitTest\Download4Http>git merge change-change
fatal: 'change-change' does not point to a commit

D:\gitTest\Download4Http>git merge change-branch
Auto-merging README.md
CONFLICT (content): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.

D:\gitTest\Download4Http>git commit -a -m "fix the merge Conflict"
[merge-branch d490c8b] fix the merge Conflict

D:\gitTest\Download4Http>git merge change-branch
Already up-to-date.

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

image

if the git find conflict . it will skip branch (no branch)  for your merge the changes

 image

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 .

image

until you finish the all conflict

image

 

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

 

文章是我原创,用英文写只为了提高下英语水平,水平很烂勿喷啊,呵呵,欢迎交流,我标明啊,编者别删拉

posted @ 2012-12-22 00:48  何锦彬  阅读(2965)  评论(0编辑  收藏  举报