Git 的origin和master分析
首先要明确一点,对git的操作是围绕3个大的步骤来展开的(其实几乎所有的SCM都是这样)
1. 从git取数据(git clone)
2. 改动代码
3. 将改动传回git(git push)
这3个步骤又涉及到两个repository,一个是remote repository,再远程服务器上,一个是local repository,再自己工作区上。其中
1, 3两个步骤涉及到remote server/remote repository/remote branch,
2涉及到local repository/local branch。git clone 会根据你指定的remote server/repository/branch,拷贝一个副本到你本地,再git push之前,你对所有文件的改动都是在你自己本地的local repository来做的,你的改动(local branch)和remote branch是独立(并行)的。Gitk显示的就是local repository。
在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 (to show all the branches git knows about)
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
$git branch -r (to show remote branches git knows about)
origin/HEAD -> origin/master
origin/master
可以发现,master就是local branch,origin/master是remote branch(master is a branch in the local repository. remotes/origin/master is a branch named master on the remote named origin)
$git diff origin/master master (show me the changes between the remote master branch and my master branch).
需要注意的是,remotes/origin/master和origin/master的指向是相同的
$git diff origin/master remotes/origin/master
git push origin master
origin指定了你要push到哪个remote
master其实是一个“refspec”,正常的“refspec”的形式为”+<src>:<dst>”,冒号前表示local branch的名字,冒号后表示remote repository下 branch的名字。注意,如果你省略了<dst>,git就认为你想push到remote repository下和local branch相同名字的branch。听起来有点拗口,再解释下,push是怎么个push法,就是把本地branch指向的commit push到remote repository下的branch,比如
$git push origin master:master (在local repository中找到名字为master的branch,使用它去更新remote repository下名字为master的branch,如果remote repository下不存在名字是master的branch,那么新建一个)
$git push origin master (省略了<dst>,等价于“git push origin master:master”)
$git push origin master:refs/for/mybranch (在local repository中找到名字为master的branch,用他去更新remote repository下面名字为mybranch的branch)
$git push origin HEAD:refs/for/mybranch (HEAD指向当前工作的branch,master不一定指向当前工作的branch,所以我觉得用HEAD还比master好些)
$git push origin :mybranch (再origin repository里面查找mybranch,删除它。用一个空的去更新它,就相当于删除了)
Git 的origin和master分析的更多相关文章
- 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用法和常见问题分析
在使用git 处理对android的修改的过程之中总结的.但不完善 Git push $ git push origin test:master // 提交本地test分支作为远程的m ...
- git学习:关于origin和master
[转载请注明出处]http://www.cnblogs.com/mashiqi 2016/10/27 本文主要是对这篇博客文章的理解. git的服务器端(remote)端包含多个repository, ...
- 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 ...
随机推荐
- Objective-C 变量和基本的数据类型
转自:http://blog.csdn.net/mengxiangyue/article/details/11369679 OC中有如下基本数据类型: int:声明整型变量 double:声明双精度变 ...
- win7+vs2010+opencv2.4.6配置
记录一下配置,省的以后还到处去找: (一) 添加环境变量://第一次使用opencv的话需要加环境变量:” %opencv%\build\x86\vc10\bin”和”%opencv%\build\c ...
- cassandra指定数据库路径
参考 https://docs.datastax.com/en/cassandra/2.1/cassandra/configuration/configCassandra_yaml_r.html 我们 ...
- 如何让电脑公司Win7系统自动关闭停止响应的程序
在注册表编辑器窗口左侧,依次展开HKEY_CURRENT_USER\ControlPanel\Desktop,选中Desktop,在右边的窗口中选择AutoEndTasks,双击打开AutoEndTa ...
- 第四章 使用Docker镜像和仓库(二)
第四章 使用Docker镜像和仓库(二) 回顾: 开始学习之前,我先pull下来ubuntu和fedora镜像 [#9#cloudsoar@cloudsoar-virtual-machine ~]$s ...
- Scatterplots 散点图
Simple Scatterplot # Simple Scatterplot attach(mtcars)plot(wt, mpg, main="Scatterplot Example&q ...
- [WPF]Slider控件常用方法
WPF的Slider控件继承自RangeBase类型,同继承自RangeBase的控件还有ProgressBar和ScrollBar,这类控件都是在一定数值范围内表示一个值的用途. 首先注意而Rang ...
- window下flask开发环境搭建
1.安装python 官网下载https://www.python.org/downloads/,按提示安装就行,记住安装目录,把它添加到系统path中. 2.安装pip 官网下载pip文件:http ...
- Unity加载模块深度解析(纹理篇)
在游戏和VR项目的研发过程中,加载模块所带来的效率开销和内存占用(即“加载效率”.“场景切换速度”等)经常是开发团队非常头疼的问题,它不仅包括资源的加载耗时,同时也包含场景物件的实例化和资源卸载等.在 ...
- 19. UIAlertController 提示框获取文本内容,打印控制台上
1.首先定义一个全局字符串变量,方便接收获取的文本内容 2. -(void)viewDidAppear:(BOOL)animated{ UIAlertController * alert = [UIA ...