zyx青岛实训day14 7/25

Git

一种分布式版本控制系统,用于跟踪和管理代码的变更

一.Git的主要功能:

二.准备git机器

修改静态ip,主机名

三.git仓库的建立:

1.安装git

root@git \~\]# yum -y install git 2.创建一个目录----用来放置git文件 \[root@git \~\]# mkdir /yy000 3.使用git指令,一定要cd到初始化之后的目录 cd到yy000目录中使用init指令初始化 \[root@git \~\]# mkdir /yy000 \[root@git \~\]# cd /yy000/ \[root@git yy000\]# ls \[root@git yy000\]# git init //将我们当前的目录变成一个工作区 4.初始化空的 Git 版本库于 /yy000/.git/ \[root@git yy000\]# vim Test.java //添加一个文件 \[root@git yy000\]# ls Test.java 5.\[root@git yy000\]# git add Test.java //将Test.java放到缓存里面 6.\[root@git yy000\]# git commit -m "新建了一个Test.java文件,这是新建的" //提交放到仓库里面 ![](https://i-blog.csdnimg.cn/direct/55e45915ff77442f880b1bcb54dfcb9d.png) 7.创建用户及邮箱 \[root@git yy000\]# git config --global user.name tjj \[root@git yy000\]# git config --global user.email 3490805063@qq.com 8.修改Test.java文件,添加一行注释 \[root@git yy000\]# echo "//这是一行jav注释,不会被编译,能提交 文件的可读性" \>Test.java \[root@git yy000\]# git log //查看日志 \[root@git yy000\]# git commit -m "这是第二次提交" \[root@git yy000\]# git log ![](https://i-blog.csdnimg.cn/direct/8739aceb16754a23acc77067d46a79c4.png) \[root@git yy000\]# echo "//我又加了一个注释" \>\> Test.java \[root@git yy000\]# git add . \[root@git yy000\]# git commit -m "将缓存中的内容提交到仓库" \[root@git yy000\]# git log ![](https://i-blog.csdnimg.cn/direct/68e0647a91ee4ecfa6ba5a0e8a9f342e.png) 四.git的基本流程 ![](https://i-blog.csdnimg.cn/direct/541b738924254409b4d50c1bdf5bc580.png) ![](https://i-blog.csdnimg.cn/direct/1c94fb7d5918437b88bca88383d87b50.png) 五.分支 1.查看当前仓库的分支 \[root@git yy000\]# git branch \* master //当前只有一个master主分支,当工作完成后,其他的分支都会合并到主分支 要求abc三个人实现一个接口 一个文件在同一时间只能被一个用户编辑 2.格式: 创建分支 git branch 分支名称 git checkout -b 分支名称 跳转分支 git checkout 分支名称 删除分支(两个分支合并的情况下) git branch -d 分支名 强制删除分支(即使该分 支尚未合并),可以使用以下命令: git branch -D 分支名 合并分支 git merge 分支名称 3.例子: (1)\[root@git yy000\]# git branch abranch //创建分支 \[root@git yy000\]# git branch //查看分支 abranch \* master (2)切换到abranch分支上 \[root@git yy000\]# git checkout abranch 切换到分支 'abranch' \[root@git yy000\]# git branch \* abranch master \[root@git yy000\]# ls Test.java (3)\[root@git yy000\]# echo "我睡觉哦" \>\> Test.java //写入内容并追加到Test.java文件中 \[root@git yy000\]# cat Test.java ![](https://i-blog.csdnimg.cn/direct/f9dad3b23de04f1289c3e265fb8fa9d5.png) (4)\[root@git yy000\]# git add . //将分支写的内容提交到缓存 (5)\[root@git yy000\]# git commit -m "我提交的" //提交新分支并注释为"我提交的" \[root@git yy000\]# git checkout master 切换到分支 'master' \[root@git yy000\]# git branch abranch \* master \[root@git yy000\]# cat Test.java ![](https://i-blog.csdnimg.cn/direct/27bdcb34b22344d28d5fb39709bf7458.png) 刚才写入的内容没有了,是因为之前是在其他分支上操作的,并非在master 上 ,所以切换回master后,显示的内容只会是master分支上的内容 \[root@git yy000\]# git checkout -b bbranch //-b在切换分支的同时创建分支 切换到一个新分支 'bbranch' \[root@git yy000\]# git branch abranch \* bbranch master \[root@git yy000\]# cat Test.java ![](https://i-blog.csdnimg.cn/direct/b49986f006a040f19d8abe88d9998b9f.png) \[root@git yy000\]# echo "我是b" \>\> Test.java \[root@git yy000\]# git branch abranch \* bbranch master \[root@git yy000\]# git checkout abranch M Test.java 切换到分支 'abranch' \[root@git yy000\]# cat Test.java ![](https://i-blog.csdnimg.cn/direct/e90fc6ee8768464b946d9bc399554dc6.png) 这两个分支可以共享 \[root@git yy000\]# git commit -m "aaa" \[root@git yy000\]# git checkout master \[root@git yy000\]# mkdir abc \[root@git yy000\]# ls abc Test.java \[root@git yy000\]# touch efg \[root@git yy000\]# git add abc/ \[root@git yy000\]# git commit -m "更像一个目录" # 位于分支 master # 未跟踪的文件: # (使用 "git add \..." 以包含要提交的内容) # # efg 提交为空,但是存在尚未跟踪的文件(使用 "git add" 建立跟踪) \[root@git yy000\]# git add efg \[root@git yy000\]# git commit -m "新增了一个efg" \[master 6386f17\] 新增了一个efg 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 efg \[root@git yy000\]# git add . \[root@git yy000\]# git commit -m "所有都提交" 当代码任务完成后,需要将更改合并回主分支。首先,切换回主分支 \[root@git yy000\]# git checkout master \[root@git yy000\]# git merge abranch //在master里面把a修改的合并到master \[root@git yy000\]# git log ![](https://i-blog.csdnimg.cn/direct/738c8caa46154d0787a33bb2a9838edc.png) 删除分支(合并的情况下) \[root@git yy000\]# git branch -d abranch \[root@git yy000\]# git branch -d bbranch \[root@git yy000\]# git branch -d cbranch \[root@git yy000\]# git branch \* master 六.分支冲突: 在合并的时候,有可能出现文件冲突(主分支修改了文件,zhangsan分支也修改了这个文件,两个分支都发生了修改,合并的时候,就不清楚以哪个分支为主,产生冲突) 手动解决: \[root@git yy000\]# echo "//我是主分支" \> Test.java \[root@git yy000\]# git checkout -b newbranch \[root@git yy000\]# echo "//我是nerbranch分支" \>\> Test.java \[root@git yy000\]# git add . \[root@git yy000\]# git commit -m "abcd" \[newbranch e71525b\] abcd 1 file changed, 2 insertions(+), 4 deletions(-) \[root@git yy000\]# git checkout master 切换到分支 'master' \[root@git yy000\]# cat Test.java //这是一行jav注释,不会被编译,能提交文件的可读性 //我又加了一个注释 我睡觉哦 我是b \[root@git yy000\]# echo "sdsdwsdew" \> Test.java \[root@git yy000\]# git add . 现在两个分支都有修改要将新分支合并到主分支 \[root@git yy000\]# git commit -m "cjdsbvdj" ![](https://i-blog.csdnimg.cn/direct/f182c9514ee9482585c07ab9face671e.png) 修改Test.java文件 \[root@git yy000\]# vim Test.java \[root@git yy000\]# git commit -m "cjdsbvdj" //再次合并 \[root@git yy000\]# git log git拉取: 再启动一台主机 安装git Yum -y install git 做一个免密登录到git主机上 ssh-keygen ssh-copy-id root@192.168.2.30 克隆192.168.2.30上的资料 \[root@git1 \~\]# git clone 192.168.2.30:/yy000/.git/ ![](https://i-blog.csdnimg.cn/direct/56a4f211099b4ab798887a51a4db006f.png) 修改内容 设置自己的姓名和邮箱 \[root@git1 yy000\]# git config --global user.name aaa \[root@git1 yy000\]# git config --global user.email [++++aaa@163.com++++](mailto:aaa@163.com) 修改内容 \[root@git1 yy000\]# touch A.class \[root@git1 yy000\]# git add . \[root@git1 yy000\]# git commit -m "aaaa" 第一次使用对方的项目 git clone 七.在码云上创建项目 ![](https://i-blog.csdnimg.cn/direct/65b23a998e1248e68f11d886bd7b4f1d.png) \[root@git1 \~\]# git clone [smt: 用于仓库部署](https://gitee.com/qingdao-jia/smt.git "smt: 用于仓库部署") \[root@git1 \~\]# cd smt/ \[root@git1 smt\]# ls README.en.md README.md \[root@git1 smt\]# mkdir -p src/main/java/ \[root@git1 smt\]# ls README.en.md README.md src \[root@git1 smt\]# touch src/main/java/Test.java \[root@git1 smt\]# git add . \[root@git1 smt\]# vim src/main/java/Test.java \[root@git1 smt\]# vim src/main/java/Test.java \[root@git1 smt\]# git add . \[root@git1 smt\]# git commit -m "水蜜桃" \[root@git1 smt\]# git push

相关推荐
feilieren30 分钟前
Docker 安装 Elasticsearch 9
运维·elasticsearch·docker·es
大数据CLUB1 小时前
基于spark的奥运会奖牌变化数据分析
大数据·hadoop·数据分析·spark
Edingbrugh.南空1 小时前
Hadoop高可用集群搭建
大数据·hadoop·分布式
智慧化智能化数字化方案1 小时前
69页全面预算管理体系的框架与落地【附全文阅读】
大数据·人工智能·全面预算管理·智慧财务·智慧预算
武子康2 小时前
大数据-33 HBase 整体架构 HMaster HRegion
大数据·后端·hbase
Java烘焙师4 小时前
架构师必备:业务扩展模式选型
mysql·elasticsearch·架构·hbase·多维度查询
诗旸的技术记录与分享15 小时前
Flink-1.19.0源码详解-番外补充3-StreamGraph图
大数据·flink
资讯分享周15 小时前
Alpha系统联结大数据、GPT两大功能,助力律所管理降本增效
大数据·gpt
G皮T17 小时前
【Elasticsearch】深度分页及其替代方案
大数据·elasticsearch·搜索引擎·scroll·检索·深度分页·search_after
TDengine (老段)17 小时前
TDengine STMT2 API 使用指南
java·大数据·物联网·时序数据库·iot·tdengine·涛思数据