默认版本仓库只有一个分支,master
git branch
直接看到当前版本仓库 有几个分支
以及有星星的哪个分支,就是你再用的
[root@tomcat-10 ~/springboot-bucket]#git branch
* master
创建分支
1. 命令先创建好分支,再切换过去
[root@tomcat-10 ~/springboot-bucket]#git branch liangliang
[root@tomcat-10 ~/springboot-bucket]#
[root@tomcat-10 ~/springboot-bucket]#
[root@tomcat-10 ~/springboot-bucket]#git branch
liangliang
* master
[root@tomcat-10 ~/springboot-bucket]#
[root@tomcat-10 ~/springboot-bucket]#
[root@tomcat-10 ~/springboot-bucket]#git branch wenjie
[root@tomcat-10 ~/springboot-bucket]#
[root@tomcat-10 ~/springboot-bucket]#
[root@tomcat-10 ~/springboot-bucket]#
[root@tomcat-10 ~/springboot-bucket]#git branch
liangliang
* master
wenjie
[root@tomcat-10 ~/springboot-bucket]#git checkout wenjie
Switched to branch 'wenjie'
[root@tomcat-10 ~/springboot-bucket]#
[root@tomcat-10 ~/springboot-bucket]#
[root@tomcat-10 ~/springboot-bucket]#git branch
liangliang
master
* wenjie
[root@tomcat-10 ~/springboot-bucket]#
[root@tomcat-10 ~/springboot-bucket]## 看懂分支的创建,切换,以及查看
- 直接创建,并且立即切换分支
[root@tomcat-10 ~/springboot-bucket]#git checkout -b yuchao
Switched to a new branch 'yuchao'
[root@tomcat-10 ~/springboot-bucket]#
[root@tomcat-10 ~/springboot-bucket]#
[root@tomcat-10 ~/springboot-bucket]#git branch
liangliang
master
wenjie
* yuchao
master分支
master和其他分支一样,就是个普通分支,没什么特点,只不过凑巧,它是默认的分支而已
合并分支(合并其他人写代码,到master上来)git merge
master作为约定俗成的默认分支,代码都合并到它这里即可。
合并wenjie分支的代码到master主干线上来
分支冲突
这里是新添加了一个文件,合并数据还好,如果是同一个文件,且同一行数据的修改,岂不是GG?
让分支提交的代码版本记录
和另外一个分支master也生成同一个文件,修改同一行数据
1.再创建一个分支,liangliang,搞破坏,且提交代码到版本仓库
[root@tomcat-10 ~/springboot-bucket]#git log -2
commit 24a0a791ace3fd40b55428aded7488eafe0ee6df
Author: pyyu <[email protected]>
Date: Fri Jul 15 23:20:58 2022 +0800
liangliang 提交了 sh文件
commit 953662cc4dd0c2f9807fb4a1256524af611712e9
Author: pyyu <[email protected]>
Date: Fri Jul 15 22:01:46 2022 +0800
v3
2.切换回master分支,别合并,先修改同一个文件,注意提交到版本仓库
3.试试这回合并代码呢?master和zhangsan修改了同一行数据
4.手工解决冲突即可
删除分支
开发完毕后,无用的分支都删掉即可
[root@tomcat-10 ~/springboot-bucket]#git branch
liangliang
* master
wenjie
yuchao
[root@tomcat-10 ~/springboot-bucket]#git branch -d liangliang
Deleted branch liangliang (was 24a0a79).
[root@tomcat-10 ~/springboot-bucket]#git branch -d wenjie
Deleted branch wenjie (was 1e07902).
[root@tomcat-10 ~/springboot-bucket]#git branch -d yuchao
Deleted branch yuchao (was 953662c).
[root@tomcat-10 ~/springboot-bucket]#git branch
* master
[root@tomcat-10 ~/springboot-bucket]#
git远程仓库
码云Gitee
配置git免密连接
# git remote add 添加一个远程仓库的别名 origin ,具体地址 https://gitee.com/yuco/linux0224.git
检查 当前本地仓库的,远程仓库配置
[root@tomcat-10 ~/springboot-bucket]#git remote -v
origin https://gitee.com/yidao620/springboot-bucket.git (fetch)
origin https://gitee.com/yidao620/springboot-bucket.git (push)
删除该记录
[root@tomcat-10 ~/springboot-bucket]#git remote remove origin
[root@tomcat-10 ~/springboot-bucket]#
[root@tomcat-10 ~/springboot-bucket]#
[root@tomcat-10 ~/springboot-bucket]#
[root@tomcat-10 ~/springboot-bucket]#git remote -v
关联你自己仓库,目前采用的是https协议,需要账户密码验证
git remote add origin https://gitee.com/yuco/linux0224.git
# git push 把本地仓库的数据,推送到origin远程仓库,推送到master分支中
git push -u origin "master"
[root@tomcat-10 ~/springboot-bucket]#git push -u origin "master"
Username for 'https://gitee.com': [email protected]
Password for 'https://[email protected]@gitee.com':
Counting objects: 2800, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (1155/1155), done.
Writing objects: 100% (2800/2800), 2.20 MiB | 640.00 KiB/s, done.
Total 2800 (delta 1062), reused 2771 (delta 1051)
remote: Resolving deltas: 100% (1062/1062), done.
remote: Powered by GITEE.COM [GNK-6.3]
To https://gitee.com/yuco/linux0224.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
[root@tomcat-10 ~/springboot-bucket]#
# 第二个玩法,基于sshkey的验证
# 结合者,本地写代码,推送到远程管理
[root@tomcat-10 ~/springboot-bucket]#
[root@tomcat-10 ~/springboot-bucket]#git log -2
commit 72c4941ea1ae99968276314ec09a9b752bf1b456
Author: pyyu <[email protected]>
Date: Fri Jul 15 23:50:12 2022 +0800
鸡汤来了
commit 7d33b7e42f3a59bec687e34748eafdd557195294
Merge: 789ed99 24a0a79
Author: pyyu <[email protected]>
Date: Fri Jul 15 23:31:07 2022 +0800
master修复了分支冲突 liangliang.sh
[root@tomcat-10 ~/springboot-bucket]#
# 修改为git协议
[root@tomcat-10 ~/springboot-bucket]#git remote -v
origin https://gitee.com/yuco/linux0224.git (fetch)
origin https://gitee.com/yuco/linux0224.git (push)
[root@tomcat-10 ~/springboot-bucket]#git remote remove origin
[root@tomcat-10 ~/springboot-bucket]#
[root@tomcat-10 ~/springboot-bucket]#
[root@tomcat-10 ~/springboot-bucket]#
[root@tomcat-10 ~/springboot-bucket]#git remote -v
[root@tomcat-10 ~/springboot-bucket]#
[root@tomcat-10 ~/springboot-bucket]##11111
# 修改为,git协议
git remote add origin [email protected]:yuco/linux0224.git
[root@tomcat-10 ~/springboot-bucket]#git remote add origin [email protected]:yuco/linux0224.git
[root@tomcat-10 ~/springboot-bucket]#
[root@tomcat-10 ~/springboot-bucket]#
[root@tomcat-10 ~/springboot-bucket]#git remote -v
origin [email protected]:yuco/linux0224.git (fetch)
origin [email protected]:yuco/linux0224.git (push)
# 推送试试
# 还得去码云中,添加当前机器的公钥
# 注意,分支得正确
[root@tomcat-10 ~/springboot-bucket]#git push -u origin master
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 328 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-6.3]
To [email protected]:yuco/linux0224.git
7d33b7e..72c4941 master -> master
Branch master set up to track remote branch master from origin.
此时可以去代码仓库中,检查该文件数据了。
克隆公开仓库
git clone https://gitee.com/xiongliding/wx.git
标签:10,git,springboot,tomcat,bucket,root,分支
From: https://www.cnblogs.com/btcm409181423/p/18288934