git-branch,查看、创建、删除分支。
创建分支(增)
How To Create a Git Branch
How do I create a new branch in Git? | Learn Version Control with Git
git branch <new-branch> # 基于当前分支 git branch <new-branch> v1.2 # 基于特定 Tag 来创建 git branch <new-branch> <base-branch> # 基于特定 Branch 来创建 git branch <new-branch> f71ac24d # 基于特定 CommitID 来创建
从 Tag 创建分支(What is git tag, How to create tags & How to checkout git remote tag(s)):
git fetch --all --tags --prune git checkout tags/<tag_name> -b <branch_name> # 先 git clone 整个仓库,然后 git checkout tag_name 就可以取得 tag 对应的代码了。 # 但是这时候 git 可能会提示你当前处于一个“detached HEAD" 状态,因为 tag 相当于是一个快照,是不能更改它的代码的,如果要在 tag 代码的基础上做修改,需要分支: # 检出某个tag git checkout -b <new-branch-name> <tag-name>
创建空分支,并切换到该空分支(Git create a empty branch from existing repository):
git checkout --orphan "<your branch name>"
删除分支(删)
-d, –delete,删除一个分支。
The branch must be fully merged in its upstream branch, or in HEAD if no upstream was set with –track or –set-upstream.
-D,–delete –force 的简写。
-r, –remotes
列出或者删除(使用了-d选项)远程追踪分支。
修改分支(改)
-m, –move
移动或者重命名分支,以及相应的reflog。
–edit-description
打开编辑器,编辑分支的描述信息。由各种其他命令使用(比如:format-patch, request-pull, merge)。
可以使用多行描述。