git——merge和rebase的区别

参考http://www.jianshu.com/p/129e721adc6egit

我在公司里看到其余同事都使用git pull --rebase拉取远程代码,而我老是用git pull,也有同事和我说过用rebase拉取代码会安全一些。可是我一直没搞清楚二者的区别,因而上网查了一些资料,就个人理解写了这篇文章。安全

1.git pull

是git fetch + git merge FETCH_HEAD 的缩写。因此,默认状况下,git pull就是先fetch,而后执行merge 操做,若是加--rebase 参数,就是使用git rebase 代替git merge。fetch

2.merge 和 rebase

merge 是合并的意思,rebase是复位基底的意思。spa

如今咱们有这样的两个分支,test和master,提交以下:code

D---E test
/
A---B---C---F master

在master执行git merge test,而后会获得以下结果:ip

D--------E
/ \
A---B---C---F----G test, master

在master执行git rebase test,而后获得以下结果:string

A---B---D---E---C '---F' test, master

 

经过上面能够看到,想要更好的提交树,使用rebase操做会更好一点。这样能够线性的看到每一次提交,而且没有增长提交节点。it

在咱们操做过程当中。merge 操做遇到冲突的时候,当前merge不能继续进行下去。手动修改冲突内容后,add 修改,commit 就能够了。table

而rebase 操做的话,会中断rebase,同时会提示去解决冲突。解决冲突后,将修改add后执行git rebase –continue继续操做,或者git rebase –skip忽略冲突。ast

相关文章
相关标签/搜索