Tekkaman

导航

 

git branch用法总结

1、创建分支

  git branch newbranch 创建一个新的本地分支,需要注意,此处只是创建分支,不进行分支切换

 

  使用 git checkcout 命令,可以切换分支。  

$ git checkout testing

 

2、分支管理

  git branch 不带参数:列出本地已经存在的分支,并且在当前分支的前面加“*”号标记。

  git branch -r 列出远程分支,例如:

  git branch -a 列出本地分支和远程分支,例如:

  

  git branch -m | -M oldbranch newbranch 重命名分支,如果newbranch名字分支已经存在,则需要使用-M强制重命名,否则,使用-m进行重命名。

 

3、删除分支

  git branch -d | -D branchname 删除branchname分支

  如果要查看哪些分支已经合并到当前分支,可以运行 git branch --merged

  

  查看所有包含未合并工作的分支,可以运行 git branch --no-merged

  

  因为它包含了还未合并的工作,尝试使用 git branch -d 命令删除它时会失败:

  

  如果真的想要删除分支并丢掉那些工作,如同帮助信息里所指出的,可以使用 -D 选项强制删除它。

 

 4、merge 合并分支

$ git checkout master
$ git merge hotfix
Updating f42c576..3a0874c
Fast-forward
 index.html | 2 ++
 1 file changed, 2 insertions(+)

 

  

误删文件

  git checkout file 可恢复。

参考:

1、https://git-scm.com/book/zh/v2/Git-分支-分支管理

2、https://www.cnblogs.com/TonyYPZhang/p/6219265.html

  

posted on 2016-02-22 14:26  Tekkaman  阅读(1345)  评论(0编辑  收藏  举报