git 使用
来源:互联网 发布:5年 java 编辑:程序博客网 时间:2024/06/16 06:38
分支(branch)的概念
Git 会使用 master 作为分支的默认名字。在若干次提交后,你其实已经有了一个指向最后一次提交对象的 master 分支,它在每次
提交的时候都会自动向前移动。如图1所示:
图 1 master 分支
创建分支(branch)
- $ git branch topic
图2 master和topic分支
现在我们的Git仓库有了两个分支,那么Git是怎么知道我们当前在哪个分支上呢?这里又将引入一个特殊的HEAD指针。在 Git 中,
它是一个指向你正在工作中的本地分支的指针。执行上面的Git命令仅仅是创建一个本地的新的分支,并不会切换到新的分支去。
如图3:
图3 当前分支为master分支
如果要切换到新的分支,还要运行下面的命令。
- $ git checkout topic
图4 当前分支为topic分支
其实,我们也可以用一个命令来实现创建并切换到新的分支。
- $ git checkout -b topic master # 在master分支的基础上创建新分支topic,并切换到topic。
- $ git branch topic release
- # 从release分支创建新分支topic
- $ git branch topic cf123ed
- # 从ID为cf123ed的commit创建新分支topic
- $ git branch topic v1.2.0
- # 从tag v1.2.0处创建新分支topic
- $ git branch --track release origin/release
- Branch release set up to track remote branch release from origin[2].
'origin/release' 分支合并进(merge)本地的'release'分支。
有时候,我们可能想创建一个没有任何提交的空分支来做一些特殊的任务,下面的命令将创建一个空的分支
- $ git symbolic-ref HEAD refs/heads/newbranch
- $ rm .git/index
- $ git clean -fdx
查看分支(branch)
- 查看当前处在哪个分支。
- $ git branch
- master
- * next
- 查看所有远程(remote)的分支
- $ git branch -r
- origin/HEAD -> origin/master
- origin/maint
- origin/master
- origin/next
- origin/pu
- origin/todo
- 查看所有分支(包括远程和本地)
- $ git branch -a
- master
- * next
- remotes/origin/HEAD -> origin/master
- remotes/origin/maint
- remotes/origin/master
- remotes/origin/next
- remotes/origin/pu
- remotes/origin/todo
- 查看每个分支的最后一个提交(commit)
- $ git branch -v
- master f8abaeb Merge branch 'maint'
- * next 2e1bdd9 Merge branch 'as/log-output-encoding-in-user-format' into next
- 查看所有分支的最后一个提交(commit)
- $ git branch -va
- master f8abaeb Merge branch 'maint'
- * next 2e1bdd9 Merge branch 'as/log-output-encoding-in-user-format' into next
- remotes/origin/HEAD -> origin/master
- remotes/origin/maint 531c8dd fixup-builtins: retire an old transition helper script
- remotes/origin/master f8abaeb Merge branch 'maint'
- remotes/origin/next 2e1bdd9 Merge branch 'as/log-output-encoding-in-user-format' into next
- remotes/origin/pu 0d79431 Merge branch 'jc/push-cas' into pu
- remotes/origin/todo 5b867dd What's cooking (2013/07 #02)
- 查看远程分支的最后一个提交(commit)
- $ git branch -vr
- origin/HEAD -> origin/master
- origin/maint 531c8dd fixup-builtins: retire an old transition helper script
- origin/master f8abaeb Merge branch 'maint'
- origin/next 2e1bdd9 Merge branch 'as/log-output-encoding-in-user-format' into next
- origin/pu 0d79431 Merge branch 'jc/push-cas' into pu
- origin/todo 5b867dd What's cooking (2013/07 #02)
删除分支(branch)
- $ git branch -d topic1
- Deleted branch topic1 (was d972dec).
- $ git branch -d topic
- error: The branch 'topic' is not fully merged.
- If you are sure you want to delete it, run 'git branch -D topic'.
- $ git branch -D topic
- Deleted branch topic (was 50590b4).
至此,我们介绍了git branch的基本概念及常用的命令。如果想更深入的理解分支及分支的管理。可以参看Pro Git的第三章-Git分支。
注:
[1] 跟踪分支(Tracking branches)是用来同步本地分支和远程分支的。如果你在’跟踪分支'(Tracking Branches)上执行推送(push)或拉
取(pull)时, 它会自动推送(push)或拉取(pull)到关联的远程分支上。
[2] origin是原始Git仓库地址的别名(alias)。
0 0
- 【git】VS2015使用Git
- 【GIT】 git rebase 使用
- 【Git】Git客户端使用
- 使用git
- git使用
- Git使用
- Git使用
- git 使用
- Git使用
- git使用
- git使用
- git 使用
- git 使用
- git 使用
- git 使用
- git 使用
- Git使用
- git 使用
- 第三方JNI SDK开发——Delphi xe5
- nagios插件之hpux系统内存检查
- 收集linux几个快捷键
- 硬盘MBR全面分析
- Android [USB]MTP的介绍?驱动如何安装?
- git 使用
- 隐藏链接和隐藏文字对seo的影响
- Android [USB]如何开关默认USB调试功能
- Android滑动菜单特效实现,仿人人客户端侧滑效果,史上最简单的侧滑实现
- 利用Ext.XTemplate自定义组件
- CODE RO RW ZI的区别
- SQL数据库恢复技术
- JavaScript - document.write(String content) writes nothing on html page
- 黑马程序员笔记:Java基础知识之this关键字的使用