Git 分支管理

使用分支意味着你可以从开发主线上分离开来,然后在不影响主线的同时继续工作

创建分支
git branch (branchname)

切换分支
git checkout (branchname)

列出分支
git branch

我们也可以使用 git checkout -b (branchname) 命令来创建新分支并立即切换到该分支下

git checkout -b test

删除分支
git branch -d (branchname)

分支合并
某分支有了独立内容,你会希望将它合并回到你的主分支
git merge test

合并冲突
$ git merge change_site
Auto-merging test.txt
CONFLICT (content): Merge conflict in test.txt
Automatic merge failed; fix conflicts and then commit the result.
$ cat test.txt 
<<<<<<< HEAD
runoob.com
新增加一行
=======
www.runoob.com
>>>>>>> change_site

我们将一个分支合并到 "master" 分支,一个合并冲突就出现了,接下来我们需要手动去修改它

$ vim test.txt 
$ cat test.txt 
www.runoob.com
新增加一行
$ git diff
diff --cc test.txt
index f84c2a4,bccb7c2..0000000
--- a/test.txt
+++ b/test.txt
@@@ -1,2 -1,1 +1,2 @@@
- runoob.com
+ www.runoob.com
 +新增加一行

在 Git 中,我们可以用 git add 要告诉 Git 文件冲突已经解决
$ git status -s
UU test.txt
$ git add test.txt 
$ git status -s
M  test.txt
$ git commit
[master 88afe0e] Merge branch 'change_site'
现在我们成功解决了合并中的冲突,并提交了结果。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DQchat

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值