git 的 origin 的含义
我们从progit 一书中可以看到:
远程仓库名字 “origin” 与分支名字 “master” 一样,在 Git 中并没有任何特别的含义一样。 同时“master”是当你运行git init时默认的起始分支名字,原因仅仅是它的广泛使用,“origin” 是当你运行 git clone 时默认的远程仓库名字。 如果你运行 git clone -o booyah,那么你默认的远程分支名字将会是 booyah/master。
我们使用 git remote -v 或者 查看.git/config 可以看到 origin 的含义。
当我们通过使用 git remote -v 命令的时候我们可以看到如下:
origin https://github.com/yaowenxu/yaowenxu.github.io.git (fetch)
origin https://github.com/yaowenxu/yaowenxu.github.io.git (push)
origin 这两种形式。
但是
origin 并不是指得是远程的仓库,而是指得是远程仓库在本地的一个指针(这个指针有可能过时的)。当我们使用使用merge 的时候,我们进行合并的时候只是上一次fetch 从远程拿到的版本。不是远程仓库的最新版本。
比如命令:
git merge origin master
指的就是将本地的远端分支与本地的master 分支进行合并。
这里 git merge origin master 可以和 git merge origin/master 进行对比
或者可以对比一下 git pull origin master 对比一下,你是不是会有新得体会。
我们或许可以再看一下 progit 上面对 远程仓库的最新的解释:
远程分支(remote branch)是对远程仓库中的分支的索引。它们是一些无法移动的本地分支;只有在 Git 进行网络交互时才会更新。远程分支就像是书签,提醒着你上次连接远程仓库时上面各分支的位置。
其实:
在clone完成之后,Git 会自动为你将此远程仓库命名为origin(origin只相当于一个别名,运行git remote –v或者查看.git/config可以看到origin的含义),并下载其中所有的数据,建立一个指向它的master 分支的指针,我们用(远程仓库名)/(分支名) 这样的形式表示远程分支,所以origin/master指向的是一个remote branch(从那个branch我们clone数据到本地),但你无法在本地更改其数据。
同时,Git 会建立一个属于你自己的本地master 分支,它指向的是你刚刚从remote server传到你本地的副本。随着你不断的改动文件,git add, git commit,master的指向会自动移动,你也可以通过merge(fast forward)来移动master的指向。
我们通过 git branch -a 可以看到所有分支:
* master
remotes/origin/HEAD -> origin/master
remotes/origin/dev
remotes/origin/master
可以发现:master 就是本地分支, origin/master 指得就是远程分支。origin/master 指得是最近一次fetch 拿下来的最新版本。
上面这个图就可以很好得讲解,我们git 所合并得是commit. git merge origin master 指得是将本地库所关联的远程仓库对应的commit id 来和本地master进行合并。
而: 本地远程仓库记录文件是:.git\refs\remotes\origin\master 本地仓库记录的文件是:.git\refs\heads\master
根据 sean-zou 的博客我们可以知道:
1、git fetch只会将本地库所关联的远程库的commit id更新至最新
2、git pull会将本地库更新至远程库的最新状态
所以 git fetch 和 git merge 共同效果并不完全等同于 git pull
或者用英文来定义一下 fetch 和 pull 更为明白:
- git fetch is the command that says “bring my local copy of the remote repository up to date.”
- git pull says “bring the changes in the remote repository where I keep my own code.”
所以可以这么 理解orgin 或者 orgin/master 这个只是远程仓库在本地仓库的一个指针。我们可以使用 git fetch 命令来进行更新。
所以在进行merge 的时候 不要忘了先进行git fetch 进行更新到最新的远程仓库。
我们借用OoBa的一个图,他详细得对比了pull 和 fetch,merge 。当然更为详细的内容可以参考《ProGit》一书。
参考文献:
1. http://www.zhanglian2010.cn/2014/07/git-pull-vs-fetch-and-merge/
2. https://git-scm.com/book/zh/v1/Git-分支
3. https://blog.csdn.net/a19881029/article/details/42245955
4. 《ProGit》- v2.1.8
git 的 origin 的含义的更多相关文章
- Git 的origin和master分析
首先要明确一点,对git的操作是围绕3个大的步骤来展开的(其实几乎所有的SCM都是这样) 1. 从git取数据(git clone) 2. 改动代码 3. 将改动传回git(g ...
- Git 的origin和master分析 push/diff/head(转)
1.origin/master : 一个叫 origin 的远程库的 master 分支 2.HEAD指向当前工作的branch,master不一定指向当前工作的branch 3.git push ...
- Git 的origin和master分析(转)
转:http://lishicongli.blog.163.com/blog/static/1468259020132125247302/ 首先要明确一点,对git的操作是围绕3个大的步骤来展开的(其 ...
- Git的origin和master分析
首先要明确一点,对git的操作是围绕3个大的步骤来展开的(其实几乎所有的SCM都是这样) 1. 从git取数据(git clone) 2. 改动代码 3. 将改动传回git(git push) 这3个 ...
- [Git] Git 的origin和master分析
转载: http://lishicongli.blog.163.com/blog/static/1468259020132125247302/ 首先要明确一点,对git的操作是围绕3个大的步骤来展开的 ...
- git push origin master、git pull出现如下错误
git push origin master出现如下错误: Counting objects: , done. Writing objects: % (/), bytes, done. Total ( ...
- git push origin与git push -u origin master的区别
$ git push origin 上面命令表示,将当前分支推送到origin主机的对应分支. 如果当前分支只有一个追踪分支,那么主机名都可以省略. $ git push 如果当前分支与多个主机存在追 ...
- git push origin master 上传失败
http://blog.csdn.net/llf369477769/article/details/51917557 按照网上教程用git把项目上传到github,但是在最后一步git push or ...
- git push origin master出错:error: failed to push some refs to
1.输入git push origin master 出错:error: failed to push some refs to 那是因为本地没有update到最新版本的项目(git上有README. ...
随机推荐
- [Swift]LeetCode266.回文全排列 $ Palindrome Permutation
Given a string, determine if a permutation of the string could form a palindrome. For example," ...
- [Swift]LeetCode285. 二叉搜索树中的中序后继节点 $ Inorder Successor in BST
Given a binary search tree and a node in it, find the in-order successor of that node in the BST. Th ...
- Android开发:修改eclipse里的Android虚拟机路径
一.发现问题: 今天打开电脑发现C盘缩了不少,这才意识到:eclipse里配置的安卓虚拟机默认放在了C盘里. 当然,在不同的电脑上可能路径有所不同,我的默认路径是:C:\Users\lenovo\.a ...
- java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.paipaixiu/com.example.paipaixiu.MASetSomeThing}: android.view.InflateException: Binary XML file line #19: Attempt to invo
这个报错是因为Android布局的控件 <view android:layout_width="match_parent" android:layout_height=&qu ...
- MySQL将utf8字符集改为utf8mb4
前言 今天在查看tomcat日志时发现了一个错误:Cause: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\x82\xF0 ...
- Python内置函数(4)——ascii
英文文档: ascii(object) As repr(), return a string containing a printable representation of an object, b ...
- SignalR学习笔记(五) 横向扩展之SQL Server
当一个Web应用程序达到一台服务器能力限制,即请求处理数量限制之后,有2种解决方案:纵向扩展和横向扩展. 纵向扩展即用更强的服务器(或虚拟机),或为当前的服务器添加更多的内存,CPU等 横向扩展即添加 ...
- .NET之消息推送(SignalR即时通讯实现)
前言 ASP .NET SignalR 是一个ASP .NET 下的类库,可以在ASP .NET 的Web项目中实现实时通信.什么是实时通信的Web呢?就是让客户端(Web页面)和服务器端可以互相通知 ...
- Chapter 5 Blood Type——6
"Yes — giving up trying to be good. I'm just going to do what I want now, and let the chips fal ...
- 痞子衡嵌入式:第一本Git命令教程(6)- 日志(log/reflog/gitk)
今天是Git系列课程第六课,上一课我们学会了Git本地提交,今天痞子衡要讲的是如何查看Git本地历史提交. 当我们在仓库里做了很多次提交之后,免不了需要回看提交记录,看看自己之前的改动.有三种Git命 ...