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 <mm@shisi.com>

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 <mm@shisi.com>

Date: Thu Jul 25 14:09:56 2024 +0800

aaa

commit f0c0fa6f64d7e7a781dadb99fc906fdb15db79fb

Author: shisi <mm@shisi.com>

Date: Thu Jul 25 11:35:41 2024 +0800

a

commit 790868543cdbe9d2e68f4da9dc40ec8983464d0c

Author: shisi <mm@shisi.com>

Date: Thu Jul 25 11:10:58 2024 +0800

第三次提交

commit c227bfbaf87ad3296ca013033afa37ffd44c81ce

Author: shisi <mm@shisi.com>

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.创造分支合并冲突

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 <file>..." 更新要提交的内容)

(使用 "git checkout -- <file>..." 丢弃工作区的改动)

修改: 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

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:

1.初始化目录:

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 "这个是文件提交"

5.在码云上实现:

6.编辑文件内容:

root@16cli yulan# vim src/main/java/test.java

root@16cli yulan# git add .

root@16cli yulan# git commit -m "修改Java文件"

7.在码云页面查看:

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#

相关推荐
愿天垂怜12 分钟前
【C++脚手架】ffmpeg 库的介绍与使用
linux·服务器·开发语言·c++·ide·git·ffmpeg
月夜的风吹雨34 分钟前
Linux 基础开发工具详解:从 yum 到 gdb 实战指南
linux·git·ubuntu·centos·vim
好运yoo1 小时前
git cherry-pick
git
不是光头 强1 小时前
Obsidian Git 插件安装与配置完全指南
git
.千余2 小时前
【C++】C++核心语法:函数重载与缺省参数原理与避坑
c语言·开发语言·c++·经验分享·笔记·git·学习
meowrain2 小时前
Git HTTPS Token 凭据配置指南
git·网络协议·https
Ws_14 小时前
Git + Gerrit 第二课:diff、暂存区与撤销修改
git
snowjlz14 小时前
鸿蒙版SVN来了!!!
git·svn·版本控制
2401_8769641316 小时前
27考研余炳森概率论|喻老李良2027资料网课
windows·git·考研·svn·eclipse·github·概率论
爱搬砖的狮子17 小时前
【Git】git repo下载使用
git