(转)git fetch + merge 和 git pull 的区别
转自:http://blog.csdn.net/a19881029/article/details/42245955
Git fetch和git pull都可以用来更新本地库,它们之间有什么区别呢?
每一个本地库下都有一个.git的隐藏文件夹,文件夹中的文件保存着跟这个本地库相关的信息
首先来看下其中的config文件
- [core]
- repositoryformatversion = 0
- filemode = false
- bare = false
- logallrefupdates = true
- symlinks = false
- ignorecase = true
- hideDotFiles = dotGitOnly
- [remote "origin"]
- url = git@github.com:seanzou88/fetch.git
- fetch = +refs/heads/*:refs/remotes/origin/*
- [branch "master"]
- remote = origin
- merge = refs/heads/master
从这个文件中我们可以了解到:
1,本地库的当前分支为master,其关联的远程库名称为origin(不同的名称可以指向同一个远程库,参见git remote命令)
2,远程库origin所在的位置为(URL):git@github.com:seanzou88/fetch.git
然后可以查看.git文件夹下的HEAD文件:
- ref: refs/heads/master
其指向.git\refs\heads\master文件
- ce71505b3626a3648b2c32ea2081d65049cad300
这个文件中保存的是本地库中最新的commit id
.git\refs文件夹很有意思,面分为3个文件夹
heads文件夹前面说过了
remotes文件夹中的每一个文件夹代表一个远程库名称(git remote),其中的每个文件关联远程库的一个分支,其中保存该分支的最新commit id
.git\logs文件夹下保存的是.git\refs文件夹下相应文件的变更记录
准备工作到此结束,下面可以具体看看git fetch和git pull之间的区别了
git fetch origin
本地的latest commit id为:ce71505b3626a3648b2c32ea2081d65049cad300
githup上的latest commit id为:ab8cd391f978fe5384a78c92001ef8ae861046f0
before:
.git\refs\heads\master
- ce71505b3626a3648b2c32ea2081d65049cad300
.git\refs\remotes\origin\master
- ce71505b3626a3648b2c32ea2081d65049cad300
.git\logs\refs\heads\master
- 0000000000000000000000000000000000000000
- ce71505b3626a3648b2c32ea2081d65049cad300
- ......
- commit (initial): first commit
.git\logs\refs\remotes\origin\master
- 0000000000000000000000000000000000000000
- ce71505b3626a3648b2c32ea2081d65049cad300
- ......
- update by push
after:
.git\refs\heads\master(不变)
.git\refs\remotes\origin\master
- ab8cd391f978fe5384a78c92001ef8ae861046f0
.git\logs\refs\heads\master(不变)
.git\logs\refs\remotes\origin\master
- 0000000000000000000000000000000000000000
- ce71505b3626a3648b2c32ea2081d65049cad300
- ......
- update by push
- ce71505b3626a3648b2c32ea2081d65049cad300
- ab8cd391f978fe5384a78c92001ef8ae861046f0
- ......
- fetch origin: fast-forward
本地库并没有变化,也就是说,git fetch只会将本地库所关联的远程库的commit id更新至最新
HEAD没有变化很容易理解,因为本地库并没有变化
git pull origin master:master
本地的latest commit id为:3643a1a65fc88ae0e9f28f12168629758d027415
githup上的latest commit id为:64df093f73294d82a3adce9694871b9fac2aecfb
before:
.git\refs\heads\master
- 3643a1a65fc88ae0e9f28f12168629758d027415
.git\refs\remotes\origin\master
- 3643a1a65fc88ae0e9f28f12168629758d027415
.git\logs\refs\heads\master
- 0000000000000000000000000000000000000000
- 3643a1a65fc88ae0e9f28f12168629758d027415
- ......
- commit (initial): first commit
.git\logs\refs\remotes\origin\master
- 0000000000000000000000000000000000000000
- 3643a1a65fc88ae0e9f28f12168629758d027415
- ......
- update by push
after:
.git\refs\heads\master
- 64df093f73294d82a3adce9694871b9fac2aecfb
.git\refs\remotes\origin\master(不变)
.git\logs\refs\heads\master
- 0000000000000000000000000000000000000000
- 3643a1a65fc88ae0e9f28f12168629758d027415
- ......
- commit (initial): first commit
- 3643a1a65fc88ae0e9f28f12168629758d027415
- 64df093f73294d82a3adce9694871b9fac2aecfb
- ......
- pull origin master:master: fast-forward
.git\logs\refs\remotes\origin\master(不变)
本地库更新至最新,git pull会将本地库更新至远程库的最新状态
由于本地库进行了更新,HEAD也会相应的指向最新的commit id
所以虽然从结果上来看,git pull = git fetch + git merge,但是从文件中保存的commit id来看,实现上不是这样实现的
为了更好的理解,画了个图:
(转)git fetch + merge 和 git pull 的区别的更多相关文章
- git pull VS git fetch&merge
使用git fetch和git pull都可以更新远程仓库的代码到本地,但是它们之间还是有区别. git fetch git fetch origin master git log -p maste ...
- git pull VS git fetch&merge(good)
从图中可以看到,git fetch和git pull的区别, git fetch 不会自动的将结果merge到本地,只是将远程版本同步到本地版本库,而不会merge到本地副本. git pull 将 ...
- git fetch, merge, pull, push需要注意的地方(转)
在git操作中,我们经常会用到fetch, merge, pull和push等命令,以下是一些我们需要注意的地方. 给大家准备了参考资料: 1. Whatʼs a Fast Forward Merge ...
- git fetch, merge, pull, push需要注意的地方
在git操作中,我们经常会用到fetch, merge, pull和push等命令,以下是一些我们需要注意的地方. 给大家准备了参考资料: 1. Whatʼs a Fast Forward Merge ...
- How to get started with GIT and work with GIT Remote Repo
https://www.ntu.edu.sg/home/ehchua/programming/howto/Git_HowTo.html#zz-7. 1. Introduction GIT is a ...
- git pull和git fetch的区别
Git中从远程的分支获取最新的版本到本地有这样2个命令:1. git fetch:相当于是从远程获取最新版本到本地,不会自动merge Git fetch origin master git log ...
- Git fetch和git pull的区别
Git中从远程的分支获取最新的版本到本地有这样2个命令:1. git fetch:相当于是从远程获取最新版本到本地,不会自动merge git fetch origin mastergit log - ...
- [转] git fetch与pull
原文: http://www.tech126.com/git-fetch-pull/ Git中从远程的分支获取最新的版本到本地有这样2个命令:1. git fetch:相当于是从远程获取最新版本到本地 ...
- git fetch和git pull(转载)
From:http://www.tech126.com/git-fetch-pull/ Git中从远程的分支获取最新的版本到本地有这样2个命令: 1. git fetch:相当于是从远程获取最新版本到 ...
随机推荐
- Lucene之索引库的维护:添加,删除,修改
索引添加 Field域属性分类 添加文档的时候,我们文档当中包含多个域,那么域的类型是我们自定义的,上个案例使用的TextField域,那么这个域他会自动分词,然后存储 我们要根据数据类型和数据的用途 ...
- python-20-迭代器是个什么东西?
前言 迭代器.生成器.装饰器都有一个“器”,但他们之间没有什么关系. 迭代器对象从集合的第一个元素开始访问,直到所有的元素被访问完结束.迭代器只能往前不会后退. 迭代器有两个基本的方法:iter() ...
- JavaBIO利用装饰器模式来组织和扩展接口
Stream接口,它直接负责字节流的传输. Reader/Writer接口,它本身不能读直接读写数据,而是以Stream接口为内部核心,在外围装饰增强,负责字符流的读写.字符和字节的转换过程必须指定字 ...
- svn cleanup 失败问题解决
将sqlite3.exe放到.svn的同级目录 4.启动cmd执行sqlite3 .svn/wc.db "select * from work_queue" 5.启动cmd执行sq ...
- mysql在node中的一些操作
mysql 服务: a) 安装wamp|xamp 开启 mysql服务 b) 安装mysql 开启服务 库操作: 客户端:软件操作(UI工具) wamp的客户端是phpmyadmin navicat ...
- Unity比较常用的数据类型
几种常见数据结构的使用情景 Array需要处理的元素数量确定并且需要使用下标时可以考虑,不过建议使用List<T> ArrayList不推荐使用,建议用List<T> List ...
- c#学习心得(2)
1.foreach与IEnumerable和IEnumerator的结合使用????? using System; using System.Collections; class Program { ...
- C# 如何获取日期时间各种方法
我们可以通过使用DataTime这个类来获取当前的时间.通过调用类中的各种方法我们可以获取不同的时间:如:日期(2019-01-09).时间(16:02:12).日期+时间(2019-01-09 16 ...
- jQuery---链式编程
链式编程 设置性操作:可以链式编程 获取性操作,不能链式,因为获取性操作,数值,字符串,返回值是不是一个jq对象. $(function () { //设置性操作:可以链式编程 //获取性操作,不 ...
- P2853 [USACO06DEC]牛的野餐Cow Picnic
------------------------- 长时间不写代码了,从学校中抽身出来真的不容易啊 ------------------------ 链接:Miku ----------------- ...