Git_分支
定义
在版本控制过程中,同时推进多个任务,为每个任务,我们就可以创建每个任务的单独
分支。使用分支意味着程序员可以把自己的工作从开发主线上分离开来,开发自己分支的时
候,不会影响主线分支的运行。对于初学者而言,分支可以简单理解为副本,一个分支就是
一个单独的副本。
优点
同时并行推进多个功能开发,提高开发效率。
各个分支在开发过程中,如果某一个分支开发失败,不会对其他分支有任何影响。失败
的分支删除重新开始即可。
操作
查看分支
基本语法
git branch -v
案例实操
创建分支
基本语法
git branch 分支名
案例实操
修改分支
-- 在 maste 分支上做修改Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)$ vim hello.txt-- 添加暂存区Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)$ git add hello.txt-- 提交本地库Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)$ git commit -m "my forth commit" hello.txt[master f363b4c] my forth commit1 file changed, 1 insertion(+), 1 deletion(-)-- 查看分支Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)$ git branch -vhot-fix 087a1a7 my third commit ( hot-fix 分支并未做任何改变)* master f363b4c my forth commit (当前 master 分支已更新为最新一次提交的版本)-- 查看 master 分支上的文件内容Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)$ cat hello.txthello git! hello atguigu! 2222222222222hello git! hello atguigu! 3333333333333hello git! hello atguigu!hello git! hello atguigu!hello git! hello atguigu!hello git! hello atguigu!hello git! hello atguigu!hello git! hello atguigu!hello git! hello atguigu!hello git! hello atguigu!hello git! hello atguigu!hello git! hello atguigu!hello git! hello atguigu!hello git! hello atguigu!hello git! hello atguigu! master testhello git! hello atguigu!
切换分支
基本语法
git checkout 分支名
案例实操
合并分支
基本语法
git merge 分支名
案例实操
在
master
分支上合并
hot-fix
分支


产生冲突
冲突产生的表现:后面状态为
MERGING
冲突产生的原因:
合并分支时,两个分支在
同一个文件的同一个位置
有两套完全不同的修改。
Git
无法替
我们决定使用哪一个。必须
人为决定
新代码内容。
查看状态
解决冲突
编辑冲突文件
删除特殊符号,决定要使用的内容
特殊符号:
<<<<<<< HEAD
当前分支的代码
=======
合并过来的代码
>>>>>>> hot-fix
添加到暂存区
执行提交
(注意:此时使用
git commit
命令时
不能带文件名
)
图解
HEAD
指向 哪个分支
,现在就在哪个
分支上。