Git --- 分支

  1. 1.分支简介
  2. 2.分支管理
    1. 2.1 创建分支
    2. 2.2 切换分支
    3. 2.3 合并分支
    4. 2.4 删除分支
    5. 2.5 合并冲突

1.分支简介

几乎每一种版本控制系统都以某种形式支持分支。使用分支意味着你可以从开发主线上分离开来,然后在不影响主线的同时继续工作。有人把 Git 的分支模型称为必杀技特性,而正是因为它,将 Git 从版本控制系统家族里区分出来。

2.分支管理

2.1 创建分支

$ git branch branchname //只是创建分支
$ git checkout -b branchname    //创建分支branchname,并切换到分支branchname上

2.2 切换分支

$ git checkout branchname

切换分支时,Git会用该分支的最后提交的快照替换工作目录的内容, 所以多个分支不需要多个目录。

2.3 合并分支

$ git merge branchname

2.4 删除分支

git branch -d branchname

2.5 合并冲突

如果在两个不同的分支中,对同一个文件的同一个部分进行了不同的修改,分支合并的时候就会产生合并冲突:

$ git merge devleop
Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.
...
<<<<<<< HEAD
...
=======
...
>>>>>>> develop

解决冲突之后,用 git add 要告诉 Git 文件冲突已经解决,然后再 git commit 提交:

$ git status -s
UU index.html
$ git add index.html
$ git status -s
M  index.html
$ git commit
[master 88afe0e] Merge branch 'develop'
本文作者:Rui
发布时间:2021-03-15, 21:34:56
原始链接:https://wrf8.github.io/posts/1519021197.html
版权声明:转载请保留原文链接及作者。

×

喜欢就点赞,疼爱就打赏