git pull、git fetch、git merge 与 git rebase

Git的fetch和pull命令都用于更新代码,fetch只下载远程仓库的更新,不合并到本地。而pull则执行fetch后自动合并,默认使用merge策略。如果分支有分歧,可以使用--rebase选项。rebase将本地提交移动到远程更新之上,保持线性历史;merge则产生分叉历史。
摘要由CSDN通过智能技术生成

参考文档:

  1. Git - git-fetch Documentation
  2. Git - git-pull Documentation
  3. Git - git-rebase Documentation

git pull 与 git fetch 的功能大致相同,起到更新代码的作用。

git fetch

git fetch 获取远端仓库分支,更新git远程追踪的分支,不进行合并。

git pull

git pull官方文档描述:

Incorporates changes from a remote repository into the current branch. If the current branch is behind the remote, then by default it will fast-forward the current branch to match the remote. If the current branch and the remote have diverged, the user needs to specify how to reconcile the divergent branches with --rebase or --no-rebase (or the corresponding configuration option in pull.rebase).

合并远端仓库到当前分支,如果当前在远程分支之后,默认采用fast-forward(快进)合并。入伙当前分支和远程分支存在在分歧,用户需要通过参数指定如何合并分支(rebase或者no-rebase)。

More precisely, git pull runs git fetch with the given parameters and then depending on configuration options or command line flags, will call either git rebase or git merge to reconcile diverging branches.

更具体的说,git pull 根据给定的参数运行 git fetch,然后根据参数或者命令行标识调用git rebase 或者 git merge合并分支。

默认的操作为git merge。

假设有如下分支:

     A---B---C master on origin
    /
D---E---F---G feature
    ^     origin/master in your repository

git pull 会获取并重现从分歧处开始的远程分支中的修改,直到当前提交(节点C)在master的顶部并将结果记录在一个新的提交中。git merge后的结果如下:

git merge: 
      A---B---C origin/master
     /         \     
D---E---F---G---H  feature

git rebase将当前分支的所有未保存在<upstream>中commit点保存到的临时区域,然后把当前分支更新到最新的原分支,并将保存的提交一个个按序添加到当前分支的顶部。

git rebase:
      A---B---C'--F'--G' feature
     /     
D---E
    ^  origin/master in your repository
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AWei_i_i

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值