博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
git fetch, git pull与git rebase比较
阅读量:4180 次
发布时间:2019-05-26

本文共 1360 字,大约阅读时间需要 4 分钟。

1.git fetch

git-fetch,从其他Git库的branch或tag或refs下载对象和引用到本地。

特性:

  • 可以同时操作多个Git库
  • 默认操作Git库origin
  • 操作后更新.git/FETCH_HEAD

 

使用格式:

  • git fetch [<options>] [<repository> [<refspec>…?]]
  • git fetch [<options>] <group>
  • git fetch --multiple [<options>] [(<repository> | <group>)…?]
  • git fetch --all [<options>]

示例:

git fetch,从默认远程库fetch所有内容
git fetch origin,从origin远程库fetch所有内容

 

2.git pull

git-pull,从其他Git库的branch或tag或refs下载对象和引用,然后合并到当前分支。

特性:

 

  • git pull等价于git fetch, git merge FETCH_HEAD
  • git pull --rebase等价于git fetch, git rebase FETCH_HEAD

使用格式:

 

 

  • git pull [options] [<repository> [<refspec>…​]]

示例:
git pull,从默认远程库fetch所有内容,然后合并到当前分支
git pull origin,从origin远程库fetch所有内容,然后合并到当前分支
git pull origin remote_branch,从origin远程库的remote_branch分支fetch所有内容,然后合并到当前分支

 

 

 

 

3.git rebase

git-rebase,在新基准的基础上,将本地基于旧基准的commits再做一遍。

特性:

  • 如果给出[<branch>],则执行git checkout <branch>
  • 相对于当前本地分支的upstream,保存本地分支的所有commits到临时工作区
  • 将当前分支reset到其对应的upstream,即执行git reset --hard <upstream>
  • 对当前分支,重新执行保存到临时工作区的所有commits。如果有冲突,则手工解决冲突后,执行git rebase --continue

使用格式:

 

 

  • git rebase [-i | --interactive] [options] [--exec <cmd>] [--onto <newbase>] [<upstream> [<branch>]]
  • git rebase [-i | --interactive] [options] [--exec <cmd>] [--onto <newbase>] --root [<branch>]
  • git rebase --continue | --skip | --abort | --quit | --edit-todo

示例:
当前分支为topic,执行git rebase master,等价于git rebase master topic。即采用最新的master作为基准,在此基础上将topic分支的本地修改再做一遍。

 

 

 

 

转载地址:http://ixlai.baihongyu.com/

你可能感兴趣的文章
JS最佳实践——单例模式
查看>>
通过pcre、zlib、openssl等库源码来源码编译nginx
查看>>
为php添加gd库支持
查看>>
$'\r': command not found
查看>>
bash脚本:一键安装MYSQL5.6
查看>>
javascript实现压缩图片
查看>>
webpack教程
查看>>
安装composer时出现 failed to open stream: HTTP request failed!的错误
查看>>
禁用HBuilderX自动更新
查看>>
linux服务器安全优化之网站目录权限设置
查看>>
自己写的ajax工具
查看>>
ajax之POST请求就404,GET请求就正常200
查看>>
error: failed to push some refs to
查看>>
删除远端git分支
查看>>
<template> cannot be keyed. Place the key on real elements instead.
查看>>
npm install chromedriver 出错
查看>>
Permission denied (publickey). fatal: Could not read from remote repository.
查看>>
Android JNI介绍
查看>>
C++字符串函数
查看>>
mknod详解
查看>>