Git 分布式版本控制系统、创建分支,跳转分支、git拉取、在码云上创建项目,进行pull 和 push、克隆码云上任意项目

目录

[1.Git 分布式版本控制系统:](#1.Git 分布式版本控制系统:)

1.安装git

2.创建目录,进行初始化

3.写入Java文件,提交文件

4.文件放入仓库

[2.创建分支,跳转分支(所有的git操作都应该工作在,指定的init 目录下进行)](#2.创建分支,跳转分支(所有的git操作都应该工作在,指定的init 目录下进行))

1.分支共享(不提交)

2.合并,先切换到主分支

3.删除分支

4.创造分支合并冲突

5.主分支和newbranch都有修改,并进行合并

6.解决冲突:

3.git拉取

1.在客户端cli主机,安装git

2.免密链接git主机:

3.克隆git主机中的yy000目录

4.检查:

5.修改内容,设置自己的账号和邮箱

[4.在码云上创建项目,进行pull 和 push:](#4.在码云上创建项目,进行pull 和 push:)

1.初始化目录:

2.回到cli客户端,克隆项目中内容

3.创建文件:

4.提交:

5.在码云上实现:

6.编辑文件内容:

7.在码云页面查看:

5.克隆码云上任意项目:


1.Git 分布式版本控制系统:

1.安装git

root@13git \~\]# yum -y install git

2.创建目录,进行初始化

root@13git \~\]# mkdir /yy000 \[root@13git \~\]# cd /yy000/ \[root@13git yy000\]# ls \[root@13git yy000\]# git init 初始化空的 Git 版本库于 /yy000/.git/ \[root@13git yy000\]# ls -a . .. .git \[root@13git yy000\]# cd .git/ \[root@13git .git\]# ls branches config description HEAD hooks info objects refs \[root@13git .git\]# cd ..

3.写入Java文件,提交文件

root@13git yy000\]# vim test.java public class Test{ public static void main(String \[\] args){ System.out.println("hello world"); } }

4.文件放入仓库

root@13git yy000\]# git log fatal: bad default revision 'HEAD' \[root@13git yy000\]# git add test.java \[root@13git yy000\]# git commit -m "新增了一个test.Java文件" \[root@13git yy000\]# git config --global user.name shisi \[root@13git yy000\]# git config --global user.email mm@shisi.com \[root@13git yy000\]# echo "你好世界" \>\> test.java \[root@13git yy000\]# git add . \[root@13git yy000\]# git commit -m "第二次" \[master(根提交) c227bfb\] 第二次 1 file changed, 6 insertions(+) create mode 100644 test.java \[root@13git yy000\]# git log commit c227bfbaf87ad3296ca013033afa37ffd44c81ce Author: shisi \ Date: Thu Jul 25 10:50:13 2024 +0800 第二次

2.创建分支,跳转分支(所有的git操作都应该工作在,指定的init 目录下进行)

root@13git yy000\]# git branch abranch \[root@13git yy000\]# git branch abranch \* master \[root@13git yy000\]# git checkout abranch 切换到分支 'abranch' \[root@13git yy000\]# git branch \* abranch master \[root@13git yy000\]# ls test.java \[root@13git yy000\]# echo "我是a" \>\> test.java \[root@13git yy000\]# cat test.java public class Test{ public static void main(String \[\] args){ System.out.println("hello world"); } } 你好世界 你好yulan 我是a \[root@13git yy000\]# git add . \[root@13git yy000\]# git commit -m "a" \[abranch f0c0fa6\] a 1 file changed, 1 insertion(+) \[root@13git yy000\]# git checkout master 切换到分支 'master' \[root@13git yy000\]# git branch abranch \* master \[root@13git yy000\]# cat test.java public class Test{ public static void main(String \[\] args){ System.out.println("hello world"); } } 你好世界 你好yulan \[root@13git yy000\]# git checkout abranch 切换到分支 'abranch' \[root@13git yy000\]# cat test.java public class Test{ public static void main(String \[\] args){ System.out.println("hello world"); } } 你好世界 你好yulan 我是a \[root@13git yy000\]#

1.分支共享(不提交)

root@13git yy000\]# git checkout -b bbranch 切换到一个新分支 'bbranch' \[root@13git yy000\]# git branch abranch \* bbranch master \[root@13git yy000\]# echo "我是b" \>\> test.java \[root@13git yy000\]# git checkout abranch M test.java 切换到分支 'abranch' \[root@13git yy000\]# cat test.java public class Test{ public static void main(String \[\] args){ System.out.println("hello world"); } } 你好世界 你好yulan 我是a 我是b \[root@13git yy000\]#

2.合并,先切换到主分支

root@13git yy000\]# git checkout master 切换到分支 'master' \[root@13git yy000\]# git branch abranch bbranch cbranch \* master \[root@13git yy000\]# git merge abranch 更新 7908685..cf43e5e Fast-forward test.java \| 2 ++ 1 file changed, 2 insertions(+) \[root@13git yy000\]# git log commit cf43e5ee9e1e32a9640689fbc1bd1762c4c60fff Author: shisi \ Date: Thu Jul 25 14:09:56 2024 +0800 aaa commit f0c0fa6f64d7e7a781dadb99fc906fdb15db79fb Author: shisi \ Date: Thu Jul 25 11:35:41 2024 +0800 a commit 790868543cdbe9d2e68f4da9dc40ec8983464d0c Author: shisi \ Date: Thu Jul 25 11:10:58 2024 +0800 第三次提交 commit c227bfbaf87ad3296ca013033afa37ffd44c81ce Author: shisi \ Date: Thu Jul 25 10:50:13 2024 +0800 第二次 \[root@13git yy000\]#

3.删除分支

root@13git yy000\]# git branch -d abranch 已删除分支 abranch(曾为 cf43e5e)。 \[root@13git yy000\]# git branch -d bbranch 已删除分支 bbranch(曾为 f0c0fa6)。 \[root@13git yy000\]# git branch -d cbranch 已删除分支 cbranch(曾为 6acdae4)。 \[root@13git yy000\]# git branch \* master ### 4.创造分支合并冲突 ![](https://i-blog.csdnimg.cn/direct/38adb920284b434da3b1310e4ea3d863.png) > \[root@13git yy000\]# echo "我是主分支,我修改了文件" \> test.java > > \[root@13git yy000\]# git checkout -b newbtanch > > M test.java > > 切换到一个新分支 'newbtanch' > > \[root@13git yy000\]# git branch > > master > > \* newbtanch > > \[root@13git yy000\]# cat test.java > > 我是主分支,我修改了文件 > > \[root@13git yy000\]# echo "我是玉兰,我要吃烤鸭" \>\> test.java > > \[root@13git yy000\]# cat test.java > > 我是主分支,我修改了文件 > > 我是玉兰,我要吃烤鸭 > > \[root@13git yy000\]# git checkout master > > M test.java > > 切换到分支 'master' > > \[root@13git yy000\]# cat test.java > > 我是主分支,我修改了文件 > > 我是玉兰,我要吃烤鸭 > > \[root@13git yy000\]# git checkout newbtanch > > M test.java > > 切换到分支 'newbtanch' > > \[root@13git yy000\]# git status > > # 位于分支 newbtanch > > # 尚未暂存以备提交的变更: > > # (使用 "git add \..." 更新要提交的内容) > > # (使用 "git checkout -- \..." 丢弃工作区的改动) > > # > > # 修改: test.java > > # > > 修改尚未加入提交(使用 "git add" 和/或 "git commit -a") > > \[root@13git yy000\]# git add . > > \[root@13git yy000\]# git commit -m "abcd" > > \[newbtanch db7438b\] abcd > > 1 file changed, 2 insertions(+), 9 deletions(-) > > \[root@13git yy000\]# git checkout master > > 切换到分支 'master' > > \[root@13git yy000\]# cat test.java > > public class Test{ > > public static void main(String \[\] args){ > > System.out.println("hello world"); > > } > > } > > 你好世界 > > 你好yulan > > 我是a > > 我是b > > \[root@13git yy000\]# echo "efg" > > efg > > \[root@13git yy000\]# echo "efg" \>\> test.java > > \[root@13git yy000\]# git add . > > \[root@13git yy000\]# git commit -m "注释说明" > > \[master b004f5f\] 注释说明 > > 1 file changed, 1 insertion(+) ### 5.主分支和newbranch都有修改,并进行合并 > \[root@13git yy000\]# git branch > > \* master > > newbtanch > > \[root@13git yy000\]# git merge newbtanch > > 自动合并 test.java > > 冲突(内容):合并冲突于 test.java > > 自动合并失败,修正冲突然后提交修正的结果。 > > \[root@13git yy000\]# ### 6.解决冲突: > \[root@13git yy000\]# vim test.java //进入文件后手动删除(dd) > > \[root@13git yy000\]# git add . > > \[root@13git yy000\]# git commit -m "合并" > > \[master c2b71d6\] 合并 > > \[root@13git yy000\]# git log ![](https://i-blog.csdnimg.cn/direct/5339e00e72974125a730458eefa711ca.png) ## 3.git拉取 ### 1.在客户端cli主机,安装git > \[root@16cli \~\]# yum -y install git ### 2.免密链接git主机: > \[root@16cli \~\]# yum -y install openssh > > \[root@16cli \~\]# yum -y install pwgen > > \[root@16cli \~\]# ssh-keygen > > \[root@16cli \~\]# ssh-copy-id root@192.168.2.13 > > \[root@16cli \~\]# ssh 192.168.2.13 > > Last login: Thu Jul 25 13:20:24 2024 from 192.168.2.2 > > \[root@13git \~\]# exit > > 登出 > > Connection to 192.168.2.13 closed. > > \[root@16cli \~\]# ### 3.克隆git主机中的yy000目录 > \[root@16cli \~\]# git clone 192.168.2.13:/yy000/.git/ > > 正克隆到 'yy000'... > > remote: Counting objects: 22, done. > > remote: Compressing objects: 100% (17/17), done. > > remote: Total 22 (delta 4), reused 0 (delta 0) > > 接收对象中: 100% (22/22), done. > > 处理 delta 中: 100% (4/4), done. > > \[root@16cli \~\]# ls ### 4.检查: > \[root@16cli \~\]# cd yy000/ > > \[root@16cli yy000\]# ls > > efg test.java > > \[root@16cli yy000\]# ls -a > > . .. efg .git test.java > > \[root@16cli yy000\]# ### 5.修改内容,设置自己的账号和邮箱 > \[root@16cli yy000\]# git config --global user.name aaa > > \[root@16cli yy000\]# git config --global user.email aaa@163.com > > \[root@16cli yy000\]# touch A.class > > \[root@16cli yy000\]# git config --global push.default matching > > \[root@16cli yy000\]# git push > > Everything up-to-date > > \[root@16cli yy000\]# git pull > > 来自 192.168.2.13:/yy000/ > > \* \[新分支\] zzz -\> origin/zzz > > Already up-to-date. ## 4.在码云上创建项目,进行pull 和 push: ![](https://i-blog.csdnimg.cn/direct/7bac8e55a9974efc84e03b39738663e6.png) ### 1.初始化目录: ![](https://i-blog.csdnimg.cn/direct/04b60733aea44a80868db2b16ae811fd.png) ### 2.回到cli客户端,克隆项目中内容 > \[root@16cli yy000\]# git clone https://gitee.com/shisim/yulan.git > > 正克隆到 'yulan'... > > remote: Enumerating objects: 4, done. > > remote: Counting objects: 100% (4/4), done. > > remote: Compressing objects: 100% (4/4), done. > > remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0 > > Unpacking objects: 100% (4/4), done. > > \[root@16cli yy000\]# ### 3.创建文件: > \[root@16cli yy000\]# cd yulan/ > > \[root@16cli yulan\]# ls > > README.en.md README.md > > \[root@16cli yulan\]# mkdir -p src/main/java/ > > \[root@16cli yulan\]# ls > > README.en.md README.md src > > \[root@16cli yulan\]# touch src/main/java/test.java > > \[root@16cli yulan\]# tree src/ > > src/ > > └── main > > └── java > > └── test.java > > 2 directories, 1 file > > \[root@16cli yulan\]# ### 4.提交: > \[root@16cli yulan\]# git add . > > \[root@16cli yulan\]# git commit -m "这个是文件提交" ![](https://i-blog.csdnimg.cn/direct/3a6e3136923941c797bfafe9feb3a623.png) ### 5.在码云上实现: ![](https://i-blog.csdnimg.cn/direct/f73bc96b9a874a67bcb55a0cf52c000f.png) ### 6.编辑文件内容: > \[root@16cli yulan\]# vim src/main/java/test.java > > \[root@16cli yulan\]# git add . > > \[root@16cli yulan\]# git commit -m "修改Java文件" ### 7.在码云页面查看: ![](https://i-blog.csdnimg.cn/direct/f1fad1fc249a49fdb8a487aacd7d19f9.png) ## 5.克隆码云上任意项目: > \[root@16cli yulan\]# cd .. > > \[root@16cli yy000\]# git clone https://gitee.com/nsdvn/nsdvn2302 > > 正克隆到 'nsdvn2302'... > > remote: Enumerating objects: 1976, done. > > remote: Total 1976 (delta 0), reused 0 (delta 0), pack-reused 1976 > > 接收对象中: 100% (1976/1976), 177.38 MiB \| 2.15 MiB/s, done. > > 处理 delta 中: 100% (1038/1038), done. > > \[root@16cli yy000\]#

相关推荐
jingshaoqi_ccc5 分钟前
GitKraken最后一个免费版本和下载地址
git·github·gitkraken·版本管理工具
乌云暮年7 分钟前
Git简单命令
git·gitee·github·batch命令
用户1259265423203 小时前
使用 Docker 搭建 Gitea 并实现 Git HTTP 自动登录
git
一只毛驴6 小时前
谈谈对git stash的理解?
git
长风破浪会有时呀10 小时前
Git 学习笔记
笔记·git·学习
中微子18 小时前
Git Rebase 详解:概念、原理与实战示例
git
荔枝吻21 小时前
【保姆级喂饭教程】Windows下安装Git Flow
windows·git·git flow
云和数据.ChenGuang1 天前
git中的指令解释
git
小Lu的开源日常1 天前
在 macOS 上设置 SSH 和 Git
git·macos·ssh
eleven_h1 天前
ERROR: Permission to Splode/pomotroid.git deni
git