原帖收藏于IT老兵驿站,传递一个IT老兵在凋零前的光和氧。
Git:git-branch命令的使用。
前言
git branch的用法。这个命令使用频度很高,还有一些没有搞明白,在这里总结梳理一下。
之前的文章题目命名都用空格,以前一直不理解git的官网为什么多加一个“-”,现在明白了,为了用作文章名和题目比较方便,解了一个惑。
正文
用法
git branch [--color[=<when>] | --no-color] [-r | -a]
[--list] [-v [--abbrev=<length> | --no-abbrev]]
[--column[=<options>] | --no-column] [--sort=<key>]
[(--merged | --no-merged) [<commit>]]
[--contains [<commit]] [--no-contains [<commit>]]
[--points-at <object>] [--format=<format>] [<pattern>…] // 列出分支(这个用法有点复杂)
git branch [--track | --no-track] [-l] [-f] <branchname> [<start-point>] // 设置分支本地和远程的关系(上流)
git branch (--set-upstream-to=<upstream> | -u <upstream>) [<branchname>] // 设置分支上流
git branch --unset-upstream [<branchname>] // 取消分支上流的设置
git branch (-m | -M) [<oldbranch>] <newbranch> // 重命名分支
git branch (-c | -C) [<oldbranch>] <newbranch> // 拷贝分支
git branch (-d | -D) [-r] <branchname>… // 删除分支
git branch --edit-description [<branchname>] //修改分支描述
git branch
有以上这么多种用法,原本我看了几遍,也感觉云山雾绕,需要加一些备注来。
常用实例
实例: 展示分支
$ git branch
* master
$ git branch -v
* master cac453c 从版本库中移除项目配置文件和日志配置文件
更为详细,加上了提交号。
$ git branch -vv
* master cac453c [origin/master] 从版本库中移除项目配置文件和日志配置文件
实例: 查看所有分支(包括远程的)
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/dev
remotes/origin/f_1123
remotes/origin/f_1268
remotes/origin/f_1316
remotes/origin/f_1317
remotes/origin/f_1346
remotes/origin/f_1347
remotes/origin/f_1490
remotes/origin/f_english
remotes/origin/master
实例: 查看远程分支
$ git branch -r
origin/HEAD -> origin/master
origin/dev
origin/f_1123
origin/f_1268
origin/f_1316
origin/f_1317
origin/f_1346
origin/f_1347
origin/f_1490
origin/f_english
origin/master
比上面那个指令少了一项master
。
更加详细,加上了上流分支的名称。