Git Common Operations Command Summary (i)
Branching is a prerequisite for all version management tools, with branches to work in parallel between different users without affecting each other, and when two of users ' respective functions are complete, they are merged together.
This article summarizes the most common commands for branch management in git:
1. Create a branch
$ git branch bra## 创建分支bra
2. Switch to Branch Bra
$ git checkout braSwitched to branch ‘bra‘
3. Create and Switch branches
$ git checkout -b rcmSwitched to a new branch ‘rcm‘## git checkout命令加上-b参数表示创建并切换,相当于以上两条命令
4. View current Branch
$ git branch bra master* rcm## 该命令会列出所有分支,当前分支前后有 * 号
5. Merging branches
[email protected] /d/appData/gitrepo (master)$ git merge rcmUpdating 05fb035..4fb9fefFast-forward second.txt | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)## git merge命令用于合并指定分支到当前分支## 注意:Fast-forward 告诉我们这次合并是快进模式,也就是直接把master指向dev的当前提交## 这种情况说明rcm分支和master分支没有冲突
6. Delete Branch
把rcm分支合并到master后,就可以把rcm分支删除掉了$ git branch -d rcmDeleted branch rcm (was 4fb9fef).
7. Merge conflicts
<<<<<<< HEAD
# #在分支合并时, sometimes it doesn't go so well
# # If there are conflicting files, you must resolve the conflict manually before committing
=======## Title # #
# #在合并分支时, sometimes it doesn't go so well
When the same file is modified on two branches, merging can cause conflicts
Bra
The results after manual resolution are:
# #在分支合并时, sometimes it doesn't go so well
# #当同一个文件在两个分支上都做了修改时 can cause conflicts when merging
# # If there are conflicting files, you must resolve the conflict manually before committing
8. View the Branch merge chart
$ git log --graph --pretty=oneline --abbrev-commit* 516dd56 conflict fixed”|| * a6e00e4 冲突测试* | 147c699 解决冲突|/* 2c1ffb3 7 合并冲突## 用git log --graph命令可以看到分支合并图
Git Common Operations Command Summary (ii)