(转)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:相当于是从远程获取最新版本到 ...
随机推荐
- 百度架构师带你进阶高级JAVA架构,让你快速从代码开发者成长为系统架构者
百度架构师带你进阶高级JAVA架构,让你快速从代码开发者成长为系统架构者 1.
- com.google.gson json字符串的序列化与反序列化
经常做协议的时候用到json,个人习惯是定义协议文档,很少在这中场景中定义类,使用对象. 这里使用一个人物有名字,性别,有一个物品列表做个简单示例记录. 序列化 JsonObject jo=new J ...
- C#实现的Check Password和锁定输错密码锁定账户
C#实现的Check Password,并根据输错密码的次数分情况锁定账户:如果输入错误3次,登录账户锁定5分钟并提示X点X分后重试登录.如果5分钟后再次输入,累计输入错误密码累计达到5次.则账户会被 ...
- sublime中写python代码
SublimeREPL插件 这个是首先要安装的,此插件主要功能是为了实现交互,在安装后需要一些简单的配置 在Preferences--> Key Bindings--> user下添加如下 ...
- MySQL基础(7) | 触发器
MySQL基础(7) | 触发器 基本语法 创建 CREATE TRIGGER trigger_name trigger_time trigger_event ON table_name FOR EA ...
- SDI011 读卡器发送非APDU指令
1 使用FFFE 发送Raw data 例如: 想要发送raw data :5140 FFFE0000025140 实际收到的是: 0B0051403E1E , (0B:PCB , 00:CID, 3 ...
- tp 框架 文本编辑器 不解析HTML标签
解析 文本编辑器 空格 {$vo.content|htmlspecialchars_decode|stripslashes|html_entity_decode}
- 为什么要进行初始化(C语言)
答案:是为了清除被释放的内存中保存的以前程序中留下的垃圾数据.
- 【剑指Offer】58:二叉树的下一个结点
题目描述 给定一个二叉树和其中的一个结点,请找出中序遍历顺序的下一个结点并且返回.注意,树中的结点不仅包含左右子结点,同时包含指向父结点的指针. 题解一:递归 //既然给了二叉树的某个结点,且二叉树存 ...
- STL-string用法
#include <string> #include <iostream> #include <cstring> #include <algorithm> ...