git分支管理、标签管理、别名设置、搭建git服务器

git本地仓库分支管理

查看分支:

[root@linux ~]# cd /data/git2/
[root@linux git2]# git branch 
* master
[root@linux git2]# ls
a.log

#当前分支下存在a.log文件

创建分支:

[root@linux git2]# git branch test

切换分支:

[root@linux git2]# git checkout test 
切换到分支 'test'
[root@linux git2]# git branch 
  master
* test
[root@linux git2]# ls
a.log

#前面的*号表示当前所在分支,新建的分支会包含master分支的文件,因为该分支是在master下创建

在test分支创建的文件提交本地仓库后不会在master分支显示:

[root@linux git2]# echo "1" > a.txt
[root@linux git2]# git add a.txt
[root@linux git2]# git commit -m "add a.txt"
[root@linux git2]# ls
a.log  a.txt
[root@linux git2]# git checkout master 
切换到分支 'master'
[root@linux git2]# ls
a.log

合并分支:

[root@linux git2]# git checkout master 
切换到分支 'master'
[root@linux git2]# git merge test 
Merge made by the 'recursive' strategy.
 a.txt | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 a.txt

#将test分支合并到master,需要先切换到master分支

合并后即可显示test分支创建的文件:

[root@linux git2]# ls
a.log  a.txt

合并后继续在test分支下修改a.txt,可以再次合并将更新后的文件同步到master分支:

[root@linux git2]# git checkout test 
切换到分支 'test'
[root@linux git2]# echo "123" >> a.txt 
[root@linux git2]# git add a.txt
[root@linux git2]# git commit -m "ch"
[test 4ae67ad] ch
 1 file changed, 1 insertion(+)
[root@linux git2]# git checkout master 
切换到分支 'master'
[root@linux git2]# git merge test 
Merge made by the 'recursive' strategy.
 a.txt | 1 +
 1 file changed, 1 insertion(+)
[root@linux git2]# ls
a.log  a.txt
[root@linux git2]# cat a.txt 
1
123

但是当两个分支分别对a.txt文件修改了不同的内容时,合并就会冲突:

[root@linux git2]# echo "aaa" >> a.txt 
[root@linux git2]# git add a.txt
[root@linux git2]# git commit -m "ch"
[master 81e7666] ch
 1 file changed, 1 insertion(+)
[root@linux git2]# git checkout test 
切换到分支 'test'
[root@linux git2]# echo "bbb" >> a.txt 
[root@linux git2]# git add a.txt
[root@linux git2]# git commit -m "ch"
[test 48b6f53] ch
 1 file changed, 1 insertion(+)
[root@linux git2]# git checkout master 
切换到分支 'master'
[root@linux git2]# git merge test 
自动合并 a.txt
冲突(内容):合并冲突于 a.txt
自动合并失败,修正冲突然后提交修正的结果。
[root@linux git2]# cat a.txt 
1
123
<<<<<<< HEAD
aaa
=======
bbb
>>>>>>> test

#两个分支的不

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值