
分支结构
1.创建分支
[root@git-10.0.0.3 ~/demo]# git branch dev
[root@git-10.0.0.3 ~/demo]# git branch
dev
* master ##当前所在分支
2.切换分支
[root@git-10.0.0.3 ~/demo]# git checkout dev
Switched to branch 'dev'
[root@git-10.0.0.3 ~/demo]# git branch
* dev
master
3.在分支上创建文件,不会到master分支
[root@git-10.0.0.3 ~/demo]# ls
file1 file2
[root@git-10.0.0.3 ~/demo]# touch file3
[root@git-10.0.0.3 ~/demo]# touch file4
[root@git-10.0.0.3 ~/demo]# git add .
[root@git-10.0.0.3 ~/demo]# git commit -m "在dev分支创建了两个文件"
[dev 15b9bbe] 在dev分支创建了两个文件
2 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 file3
create mode 100644 file4
[root@git-10.0.0.3 ~/demo]# git checkout master
Switched to branch 'master'
[root@git-10.0.0.3 ~/demo]# ls
file1 file2
4.将master分支合并到dev分支上
[root@git-10.0.0.3 ~/demo]# git checkout dev
Switched to branch 'dev'
[root@git-10.0.0.3 ~/demo]# ls
file1 file2 file3 file4
[root@git-10.0.0.3 ~/demo]# git merge master -m "将master分支更新到dev分支"
Merge made by the 'recursive' strategy.
file5 | 0
file6 | 0
2 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 file5
create mode 100644 file6
[root@git-10.0.0.3 ~/demo]# ls
file1 file2 file3 file4 file5 file6
[root@git-10.0.0.3 ~/demo]# git log --oneline
dca85e6 将master分支更新到dev分支
6fe09da 在master创建了两个文件
adf8613 在dev分支创建了两个文件
08121a7 创建了两个文件
5.将分支内容拉去到master上
[root@git-10.0.0.3 ~/demo]# git merge dev
Updating 6fe09da..dca85e6
Fast-forward
file3 | 0
file4 | 0
2 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 file3
create mode 100644 file4
6.分支合并时处理办法

问题产生原因
[root@git-10.0.0.3 ~/demo]# touch init.html
[root@git-10.0.0.3 ~/demo]# echo AA BB CC >init.html
[root@git-10.0.0.3 ~/demo]# git add .
[root@git-10.0.0.3 ~/demo]#git commit -m "测试"
[root@git-10.0.0.3 ~/demo]# git checkout dev
Switched to branch 'dev'
[root@git-10.0.0.3 ~/demo]# touch init.html
[root@git-10.0.0.3 ~/demo]# echo AA BB DD >init.html
[root@git-10.0.0.3 ~/demo]# git add .
[root@git-10.0.0.3 ~/demo]#git commit -m "测试"
[root@git-10.0.0.3 ~/demo]# git merge master
Auto-merging init.html
CONFLICT (add/add): Merge conflict in init.html

冲突文件
解决办法:将不同内容改一下即可。