赞
踩
最近项目迭代需求有点多,然后又有个需求虽然已经上到了staging,但是又没法上prodution;但是有其他短小的需求要上prodution,所以这个时候就需要利用git版本控制的优点之一每个计算机都是一个完整仓库,来实现此次上线;
git pull origin master
git checkout -b zfxmaster
compare with current
git commit -b ‘’
git checkout master
git merge zfxmaster
git push origin master:zfxmaster
但是这里在执行checkout的时候,我突然迟疑了,这个项目remote有5个branch,但是我想要与master保持一致,我这个要怎么写呐?接下来就看看git checkout 的用法
git checkout:迁出某个分支的特定版本。默认的是将HEAD指定的分支设置为当前分支
具体的参数介绍可以点击参考文档
Git必须知道当前版本是哪个版本,在Git中,用HEAD表示当前版本,也就是最终指向了一个40位的HASH值,我就按照这个项目来看看HEAD中的配置
打开看看这个文件内容:
ref: refs/heads/zfxmaster //这里显示的时本地仓库,当前所处的分支
这里的refs/heads,目录下是关于本地仓库的所有分支;找到zfzmaster文件打开,这里是当前分支的最后一次commmitid,因为该分支是从本地的master分支检出的,所以你也可以查看一下heads/master的hash值,是与zfxmaster一致的;
所以我使用checkout -b时没有指定远程分支,那就是创建了一个与当前我所在分支(HEAD中的commmit ID)一致的分支。
关于 checkout -b 就不过多说了,这是文档上的描述:
git checkout -b|-B <new_branch> []
Specifying -b causes a new branch to be created as if git-branch[1] were called and then checked out. In this case you can use the --track or --no-track options, which will be passed to git branch. As a convenience, --track without -b implies branch creation; see the description of --track below.
If -B is given, <new_branch> is created if it doesn’t exist; otherwise, it is reset. This is the transactional equivalent of
$ git branch -f []
$ git checkout
that is to say, the branch is not reset/created unless “git checkout” is successful.
其实也是相当于两个命令的缩写:
git branch zfxmaster
git checkout zfxmaster
当你不想新建的分支与本地某分支一致的话,你可以在使用checkout时,使用参数来确定检出哪个分支
git checkout -b zfxmaster origin/master
从远程的master分支检出到本地的zfxmaster上,并切换到新建的本地zfxmaster分支上
本地的项目中,一直都保留着一个master分支,并关联远程的master分支。本地的master分支,你可以当作是个干净的主线,每次新来一个需求的时候你都可以以该分支为基准,新建一个分支进行开发,最后进行合并,并由这个基准分支(本地master)提交到远程;
具体的专业信息你可以参照文档:Git-分支-分支的新建与合并
checkout的本质是拷贝了refs/heads/下的一个头指针(refs/heads),如下所示:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。