git fetch和git pull的区别

原文: http://www.tech126.com/git-fetch-pull/ 
Git中从远程的分支获取最新的版本到本地有这样2个命令:
1.  git fetch :相当于是从远程获取最新版本到本地,不会自动merge
<pre name="code" class="prettyprint" style="line-height:25px; padding-top:2px; padding-right:2px; padding-bottom:2px; padding-left:2px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(136,136,136); border-right-color:rgb(136,136,136); border-bottom-color:rgb(136,136,136); border-left-color:rgb(136,136,136)"><span class="pln" style="color:#000000;line-height:23px;">git fetch origin master</span><br style="line-height:23px" /><span class="pln" style="color:#000000;line-height:23px;">git log </span><span class="pun" style="color:#66660;line-height:23px;">-</span><span class="pln" style="color:#000000;line-height:23px;">p master</span><span class="pun" style="color:#66660;line-height:23px;">..</span><span class="pln" style="color:#000000;line-height:23px;">origin</span><span class="pun" style="color:#66660;line-height:23px;">/</span><span class="pln" style="color:#000000;line-height:23px;">master</span><br style="line-height:23px" /><span class="pln" style="color:#000000;line-height:23px;">git merge origin</span><span class="pun" style="color:#66660;line-height:23px;">/</span><span class="pln" style="color:#000000;line-height:23px;">master</span>
 
      以上命令的含义: 
  
   首先从远程的origin的master主分支下载最新的版本到origin/master分支上
   然后比较本地的master分支和origin/master分支的差别
   最后进行合并
   上述过程其实可以用以下更清晰的方式来进行:
<pre name="code" class="prettyprint" style="line-height:25px; padding-top:2px; padding-right:2px; padding-bottom:2px; padding-left:2px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(136,136,136); border-right-color:rgb(136,136,136); border-bottom-color:rgb(136,136,136); border-left-color:rgb(136,136,136)"><p style="line-height:25px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"><span style="font-family:'Trebuchet MS',Tahoma,Arial;font-size:12px;color:#333333;line-height:23px"><span style="line-height:19px"><span class="pln" style="color:#000000;line-height:23px;">git fetch origin master</span><span class="pun" style="color:#66660;line-height:23px;">:</span><span class="pln" style="color:#000000;line-height:23px;">tmp</span></span></span><br style="line-height:25px" /><span style="font-family:'Trebuchet MS',Tahoma,Arial;font-size:12px;color:#333333;line-height:23px"><span style="line-height:19px"><span class="pln" style="color:#000000;line-height:23px;">git diff tmp </span></span></span><br style="line-height:25px" /><span style="font-family:'Trebuchet MS',Tahoma,Arial;font-size:12px;color:#333333;line-height:23px"><span style="line-height:19px"><span class="pln" style="color:#000000;line-height:23px;">git merge tmp</span></span></span></p>
 
      从远程获取最新的版本到本地的test分支上 
  
   之后再进行比较合并
2.  git pull :相当于是从远程获取最新版本并merge到本地
<pre name="code" class="prettyprint" style="line-height:19px; padding-top:2px; padding-right:2px; padding-bottom:2px; padding-left:2px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(136,136,136); border-right-color:rgb(136,136,136); border-bottom-color:rgb(136,136,136); border-left-color:rgb(136,136,136); color:rgb(51,51,51); font-family:'Trebuchet MS',Tahoma,Arial; font-size:13px"><span class="pln" style="color:#000000;line-height:23px;">git pull origin master</span>
 
  上述命令其实相当于git fetch 和 git merge 
  
在实际使用中,git fetch更安全一些
因为在merge前,我们可以查看更新情况,然后再决定是否合并
结束


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值