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#

相关推荐
Lydro1 小时前
CentOS 7 安装高版本git
git·centos 7
guwentian10 小时前
Git Worktree 实战:用并行多 Agent 把开发提速 N 倍
大数据·git·elasticsearch·wroktree
不吃鱼的羊13 小时前
Git识别未修改的文件有修改
git
蓝黑墨水15 小时前
一个git问题的处理
git
互联网中的一颗神经元18 小时前
21 — 额外命令:同时开两个窗口、自动检查哨
git
_道隐_21 小时前
git stash save 和 git stash push有什么区别?
git
_道隐_1 天前
git stash如何pop指定的stash change?
git
PC2005-cloud1 天前
Git学习笔记:GitHub Git Data API 完全指南,用 Go 操控 Git 底层对象
笔记·git·学习
Python私教2 天前
AI 并行编码的 Worktree 生命周期:创建、隔离与安全回收
人工智能·git
互联网中的一颗神经元2 天前
16 — 改写历史 rebase:搬家到新楼层,不是合并
git