分支定义
分支可以理解成 独立开发功能的 小房间。
分支操作
# 创建分支
$ git branch 分支名
# 查看分支
$ git branch
# 切换分支
$ git checkout 分支名
# 创建+切换分支
$ git checkout -b 分支名
# 合并某分支到当前分支
$ git merge 分支名
# 删除某分支
$ git branch -d 分支名
合并分支解决冲突
当前分支1 分支2 前提分支1和分支2都进行了代码修改。
将分支2的内容合并到分支1
# 1. 切换到当前分支1
$ git checkout 分支1
# 2. 和分支2进行合并
$ git merge 分支2
# 3. 执行第二步后出现冲突(CONFLICT)
$ git merge dev
Auto-merging hello.py
CONFLICT (content): Merge conflict in hello.py
Automatic merge failed; fix conflicts and then commit the result.
# 4. 解决方案:
print 'first'
<<<<<<< HEAD
print 'master second'
=======
print 'dev second'
>>>>>>> dev
1. 编辑合并分支1和分支2的内容
2. 修改好之后,$ git add 文件名
3. $ git commit -m "描述信息"