git fetch和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和git pull之间的区别--转载的更多相关文章
- 详解git fetch与git pull的区别(实操)
感谢原文作者:R-H-R 原文链接:https://blog.csdn.net/riddle1981/article/details/74938111 git fetch和git pull都可以将远端 ...
- Git fetch和git pull的区别, 解决Git报错:error: You have not concluded your merge (MERGE_HEAD exists).
Git fetch和git pull的区别, 解决Git报错:error: You have not concluded your merge (MERGE_HEAD exists). Git fet ...
- get merge --no-ff和git merge区别、git fetch和git pull的区别
get merge --no-ff和git merge区别 git merge -–no-ff可以保存你之前的分支历史.能够更好的查看 merge历史,以及branch 状态. git merge则不 ...
- git:Git fetch和git pull的区别, 解决Git报错:error: You have not concluded your merge (MERGE_HEAD exists).
Git fetch和git pull的区别, 解决Git报错:error: You have not concluded your merge (MERGE_HEAD exists). 解决办法一:保 ...
- git pull、git fetch、git merge、git rebase的区别
一.git pull与git fetch区别 1.两者的区别 两者都是更新远程仓库代码到本地. git fetch相当于是从远程获取最新版本到本地,不会自动merge. 只是将远程仓库最新 ...
- Git fetch和git pull的区别
Git中从远程的分支获取最新的版本到本地有这样2个命令:1. git fetch:相当于是从远程获取最新版本到本地,不会自动merge git fetch origin mastergit log - ...
- Git fetch和git pull的区别(转)
原文: http://www.tech126.com/git-fetch-pull/ Git中从远程的分支获取最新的版本到本地有这样2个命令:1. git fetch:相当于是从远程获取最新版本到本地 ...
- 关于git fetch 和git pull 的区别
1.fetch 相当于是从远程获取最新版本呢到本地,不会自动merge. git fetch origin master:tmpgit diff tmp git merge tmp 2. git pu ...
- [Git] Git fetch和git pull的区别
reference : http://blog.csdn.net/hudashi/article/details/7664457 Git中从远程的分支获取最新的版本到本地有这样2个命令:1. git ...
随机推荐
- LeetCode(7) - Reverse Integer
题目的要求就是要反转一个Integer,例如输入123,则输出321,这一题比较tricky的地方就是它有可能越界,就是说1234567899,反过来是9987654321是一个越界的Integer, ...
- Context3D 不可用
打开项目文件夹中的html-template,并找到index.template.html,右键使用TextEditor编辑,在params.allowfullscreen=”true”:后面加上pa ...
- miracast 协议wifi display
看wifi direct display标准的地方: http://www.wi-fi.org/discover-wi-fi/specifications Miracast依赖的Wi-Fi技术项[②] ...
- 安装Win7和Office2010并激活
1. 下载Win7 建议安装原版的win7 SP1 64位中文旗舰版,不建议安装Ghost版本,之前用U盘安装Ghost版本一直失败.原版的下载地址为,选其中一个地址下载就行了. ed2k://|fi ...
- SUSE linux ,liveUSB制作方法
下载了ubuntu 11.04,ubuntu11.10,fedora15,kubuntu 11.04,linuxmint-11,还有suse的kde和gnome的桌面版镜像,其他的都很方便的做成了li ...
- JQuery与GridView控件结合示例
JQuery是一种非常强大的客户端JS编程技术,这里不想过多阐述它的相关背景知识,只想简单演示一下如何与asp.net的控件结合开发. 比如,我们要做一个下面如图所示的功能,效果是状态.编号.数字1. ...
- LIS (最长上升子序列)
LIS两种写法 O(n^2) dp[i]表示以a[i]结尾的为LIS长度 #include <algorithm> #include <iostream> #include & ...
- UVaLive 6801 Sequence (计数DP)
题意:给定一个序列,有 n 个数,只有01,然后你进行k次操作,把所有的1变成0,求有多种方法. 析:DP是很明显的,dp[i][j] 表示进行第 i 次操作,剩下 j 个1,然后操作就两种,把1变成 ...
- Excel合并单元格数据
1.=A1&B1 2.=CONCATENATE(A1,B1)
- javac 命令
HelloWorld.java:1: 需要为 class.interface 或 enum 锘缝ublic class HelloWorld{ ^ 1 错误 这个错误出现的原因主要是在中文操作系统中, ...