git常用命令(二)

来源:互联网 发布:php 获取url中的参数 编辑:程序博客网 时间:2024/04/29 04:57

本地仓库中git的分支相关的命令

git branch 查看当前的分支,带“*”表示当前所在的分支[root@miner_k git]# git branch* master

增加和切换分支

格式:git checkout -b <branch_name> 创建分支并切换到新的分支或者git branch <branch_name>   创建新的分支git  checkout  <branch_name> 切换已经存在的分支[root@miner_k git]# git checkout -b devA   3.txtSwitched to a new branch 'dev'[root@miner_k git]# git branch* dev  master[root@miner_k git]# git branch test[root@miner_k git]# git checkout testA   3.txtSwitched to branch 'test'[root@miner_k git]# git branch  dev  master* test

合并分支

git merge  <branch_name>   将dev分支合并到当前分支中(Fast-forward模式)git merge --no-ff -m "描述" <branch_name>   (非Fast-forward模式)[root@miner_k git]# git branch  dev* master  test[root@miner_k git]# git merge testUpdating 1295784..cd4262dFast-forward 3.txt    |    2 ++ test.txt |    1 + 2 files changed, 3 insertions(+), 0 deletions(-) create mode 100644 3.txt create mode 100644 test.txt

删除分支

使用场景: 当某一个项目的功能增加完成,可以将该分支合并然后删除(-d)
当某一个功能开发一段时间之后,由于某些原因需要中图放弃,需要直接删除(-D)

git branch -d <branch_name> 删除已经合并的分支git branch -D <branch_name> 删除未合并的分支[root@miner_k git]# git branch  dev* master  test[root@miner_k git]# git branch -d testDeleted branch test (was cd4262d).[root@miner_k git]# git branch -d deverror: The branch 'dev' is not fully merged.If you are sure you want to delete it, run 'git branch -D dev'.[root@miner_k git]# git branch -D devDeleted branch dev (was 260a3ef).

解决分支合并的冲突

[root@miner_k git]# git merge dev
Auto-merging 3.txt
CONFLICT (content): Merge conflict in 3.txt
Automatic merge failed; fix conflicts and then commit the result.
先解决冲突,让后在合并就行了。

扩展链接

本地连接到github的仓库(一般常使用github的账号和密码确认身份的方式连接github的仓库)
git的基本命令简介
git中标签的使用
github官网使用

0 0
原创粉丝点击