首页 > 其他分享 >版本控制系统

版本控制系统

时间:2024-07-07 17:52:25浏览次数:6  
标签:10 shell tomcat root 控制系统 git 版本 my

GIT 分布式版本控制系统

分布式版本控制,没有中央服务器的概念,每个人都有自己的版本库,因此每个人在工作时候,不需要联网,版本库本地即可管理。
既然每个人都是一个完整的版本库,同事之间如果需要协作开发,就需要找一个用于“交换文件”的中央服务器,这个服务器不存在也不影响大家干活,只是用于交换文件内容。
GIT最强大的功能还有分支管理,远甩SVN等软件。

git特点

1. git是分布式的,特点是保存本地文件的元数据(meta data,文件属性等),将本地文件所有的的元信息,记录在git repo里的.git隐藏文件夹中。

2. git的使用可以不用网络,因为本地版本控制仓库就在你自己机器上,每一个人就是一个完成的版本库。
只不过是最终将你的本地仓库,作为一个分支,推送、合并到一个统一的线上代码仓库主干线即可,实现代码集成。

windows装git

https://git-scm.com/download/win

linux\macos 装git

yum install git -y

查看版本

git --version

git身份设置

因为git是分布式版本控制系统,因为要区分出,到底是谁进行了版本管理,也就是提交的版本记录,都是有名字,有时间的
因此用git之前要先设置git的身份设置

一般用如下命令,设置身份即可
# 给git设置配置信息 --global 参数,身份信息,会写入 ~/.gitconfig

git config --global user.name "lisa"
git config --global user.email "[email protected]"
# 开启git命令的颜色支持
git config --global color.ui true

查看配置文件
cat ~/.gitconfig

查看当前机器的git身份配置信息
[root@web-7 ~/git-learn]#cat ~/.gitconfig
[user]
	name = wenjie
	email = [email protected]
[color]
	ui = true

列出git设置
[root@web-7 ~/git-learn]#git config --list
user.name=wenjie
[email protected]
color.ui=true

git身份设置命令集合

yum install git -y  安装git

git --version  查看git版本

git config --system --list 查看系统所有linux用户的通用配置,此命令检查/etc/gitconfig

git config --global --list 查看当前linux用户的配置,检查~/.gitconfig文件

git config --local --list 查看git目录中的仓库配置文件,.git/config文件

git config --global user.name "pyyu"  配置当前linux用户全局用户名,这台机器所有git仓库都会用这个配置

git config --global user.email "[email protected]"  配置当前linux用户全局邮箱

git config --global color.ui true 配置git语法高亮显示

git config --list 列出git能找到的所有配置,从不同的文件中读取所有结果

git config user.name  列出git某一项配置

git help 获取git帮助

man git man手册

git help config 获取config命令的手册

git实践原理

git本地仓库,也就是一个文件夹,这个目录下的所有内容都被git工具管理,记录了所有文件的元数据。

你在这个本地仓库中所有对文件的修改,删除,都会被git记录下状态,便于历史记录跟踪,以及还原文件状态。

三个git使用的场景

git的使用流程套路

1. git init . 初始化本地仓库

2.  写代码,如 hello.sh

3. 通过git add . 进行本地文件追踪管理,文件信息被记录到 暂存区

4.  git commit -m '注释'  ,将暂存区的数据,提交到local repo  本地仓库,进行第一个版本的记录

1:本地已经写好了代码,需要用git去管理

[root@web-7 ~/git-learn/my_shell]#ls
hello.sh
[root@web-7 ~/git-learn/my_shell]#ls -a
.  ..  hello.sh

没有被git进行管理,使用git进行,从0 到1管理

1. 初始化生成 .git文件夹
[root@web-7 ~/git-learn/my_shell]#git init .
初始化了一个空的git仓库 再 /root/git-learn/my_shell/.git/
Initialized empty Git repository in /root/git-learn/my_shell/.git/

这个时候,/root/git-learn/my_shell    该文件夹,就被git管理了,再这个目录下对文件的修改类操作,就会被git进行记录了

命令,查看git工作区的状态

[root@web-7 ~/git-learn/my_shell]#git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	hello.sh
nothing added to commit but untracked files present (use "git add" to track)

2追踪文件属性
[root@web-7 ~/git-learn/my_shell]#git add hello.sh
[root@web-7 ~/git-learn/my_shell]#
[root@web-7 ~/git-learn/my_shell]#
[root@web-7 ~/git-learn/my_shell]#
[root@web-7 ~/git-learn/my_shell]#git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#	new file:   hello.sh

3提交版本了,提交第一个版本
[root@web-7 ~/git-learn/my_shell]#git commit -m 'v1 第一次提交'
[master (root-commit) 67d8f28] v1 第一次提交
 1 file changed, 1 insertion(+)
 create mode 100644 hello.sh

4查看版本记录日志
[root@web-7 ~/git-learn/my_sh]#git log

[root@web-7 ~/git-learn/my_sh]#git reflog    可以查看所有的历史记录




从零新建git本地仓库,编写代码

mkdir /home/yuchao/

[root@cicd-99 ~]#git init  /home/yuchao/happy_linux
Initialized empty Git repository in /home/yuchao/happy_linux/.git/

此步会在当前路径创建happy_linux文件夹,happy_linux文件夹中包含了.git的初始化文件夹,所有配置
写代码然后git add 和 git commit -m "备注"

版本回退,基于commit——ID切换状态

回到指定的提交记录id中

# 回到指定的提交id记录中
git reset --hard 87d1da5

# 回到上一次提交的版本id中
[root@web-7 ~/git-learn/my_website]#git reset --hard HEAD^

#回到 上 上 一次的提交版本id中 
[root@web-7 ~/git-learn/my_website]#git reset --hard HEAD^^

root@web-7 ~/git-learn/my_website]#
[root@web-7 ~/git-learn/my_website]#git reset --hard HEAD^
HEAD is now at 0ecf4f1 写了一个hello.log

克隆远程仓库中的代码

基于git clone命令,直接下载一个远程仓库的代码

gitee码云,https://gitee.com/ 
https://gitee.com/jumpserver/jumpserver?_from=gitee_search

[root@web-7 /tmp]#git clone https://gitee.com/jumpserver/jumpserver.git
Cloning into 'jumpserver'...
remote: Enumerating objects: 72601, done.
remote: Counting objects: 100% (61413/61413), done.
remote: Compressing objects: 100% (16221/16221), done.
remote: Total 72601 (delta 43226), reused 60492 (delta 42372), pack-reused 11188
Receiving objects: 100% (72601/72601), 64.55 MiB | 12.85 MiB/s, done.
Resolving deltas: 100% (50717/50717), done.
[root@web-7 /tmp]#

2个办法确认它是一个git本地仓库,如何确认?

  1. 看有没有.git 文件夹 2. 执行git 命令试试
# 查看日志,简写
# 记录只显示缩略的一行 
git log --oneline 

# 查看最新的4个记录
git log --oneline  -4

图解git工作流

git命令实践

1 从零初始化git本地仓库

git init /my_code/

查看本地仓库的状态

[root@tomcat-10 /my_code]#echo "123123123" > 打起精神来.log
[root@tomcat-10 /my_code]#
[root@tomcat-10 /my_code]#
[root@tomcat-10 /my_code]#
[root@tomcat-10 /my_code]#git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	"\346\211\223\350\265\267\347\262\276\347\245\236\346\235\245.log"
nothing added to commit but untracked files present (use "git add" to track)

加入暂存区

[root@tomcat-10 /my_code]#git add 打起精神来.log 

[root@tomcat-10 /my_code]#git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#	new file:   "\346\211\223\350\265\267\347\262\276\347\245\236\346\235\245.log"
#
[root@tomcat-10 /my_code]#

从暂存区移除文件

本地仓库的细节知识

场景1,本地仓库,以及有了第一个版本

[root@tomcat-10 /my_shell]#git add hehehehe.sh 

[root@tomcat-10 /my_shell]#
[root@tomcat-10 /my_shell]#git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#	new file:   hehehehe.sh
#
[root@tomcat-10 /my_shell]#
[root@tomcat-10 /my_shell]#git log
commit 3b4420b805b297239d9b3adc8c8605e593cab5d9
Author: pyyu <[email protected]>
Date:   Fri Jul 15 18:56:09 2022 +0800

    那我走?



场景2,本次仓库是空的,还没有任何版本

[root@tomcat-10 /my_shell]## 2个选择,1是提交一个版本  2是撤销暂存区的记录 ,看懂22222
[root@tomcat-10 /my_shell]#
[root@tomcat-10 /my_shell]#git log
fatal: bad default revision 'HEAD'

[root@tomcat-10 /my_shell]#git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#	new file:   xixixixix.sh
#

[root@tomcat-10 /my_shell]#git rm --cached xixixixix.sh 
rm 'xixixixix.sh'
[root@tomcat-10 /my_shell]#
[root@tomcat-10 /my_shell]#git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	xixixixix.sh
nothing added to commit but untracked files present (use "git add" to track)

[root@tomcat-10 /my_shell]## git add  git commit

[root@tomcat-10 /my_shell]## 再空本地仓库中的,撤销动作  git rm --cached file  

重新跟踪、提交文件

基于撤销的动作基础上,再次版本提交

[root@tomcat-10 /my_shell]#git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	hehehehe.sh
nothing added to commit but untracked files present (use "git add" to track)

[root@tomcat-10 /my_shell]#git add hehehehe.sh 

[root@tomcat-10 /my_shell]#git commit -m 'heheheh 那我走?'
[master 0c750ff] heheheh 那我走?
 1 file changed, 1 insertion(+)
 create mode 100644 hehehehe.sh

[root@tomcat-10 /my_shell]#git status
# On branch master
nothing to commit, working directory clean

[root@tomcat-10 /my_shell]#git log
commit 0c750ff9db54f7d7a1397c413753236f3f9dfe67
Author: pyyu <[email protected]>
Date:   Fri Jul 15 19:03:27 2022 +0800

    heheheh 那我走?

commit 3b4420b805b297239d9b3adc8c8605e593cab5d9
Author: pyyu <[email protected]>
Date:   Fri Jul 15 18:56:09 2022 +0800

    那我走?

git如何查看文件状态

git status

基于git的文件重命名

如果你要在某个版本仓库下,修改文件的名字,如何改(修改,删除,都会对文件的元属性进行修改)
git mv
git rm 
俩命名

# 需求,记住如下正确改名的玩法即可


1. 原本的数据是
[root@tomcat-10 /my_shell]#ls
hehehehe.sh  xixixixix.sh

这俩文件都被提交为了一个版本记录,此时暂存区是空了


2. 需求是 修改xixixixix.sh 改为 java后缀
正确玩法应该是
git mv xixixixix.sh xixixixi.java

git commit -m '于超 重命名了 xixixi.sh 为xixix.java'

基于git的删除文件

记住,再git本地仓库中,只要是被git管理的,记录为某个版本的文件,就不能直接
rm去删

先记住正确删除的玩法


git rm去删

[root@tomcat-10 /my_shell]#git rm *.log
rm '1.log'
rm '2.log'
rm '3.log'
rm '4.log'
rm '5.log'
[root@tomcat-10 /my_shell]#
[root@tomcat-10 /my_shell]#
[root@tomcat-10 /my_shell]#
[root@tomcat-10 /my_shell]#git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#	deleted:    1.log
#	deleted:    2.log
#	deleted:    3.log
#	deleted:    4.log
#	deleted:    5.log


再提交一个存档,版本

git版本回退

# 回到上一次提交的版本id中
[root@web-7 ~/git-learn/my_website]#git reset --hard HEAD^

#回到 上 上 一次的提交版本id中 
[root@web-7 ~/git-learn/my_website]#git reset --hard HEAD^^

穿梭未来(如何再git所有的版本中,来回切换)

回到了2018年

如何再回去?回到今天2022年提交的 v1 v2 v3 找回来。

版本回退的核心点,找到commit id把

git log只能看到当前HEAD指向的最新的记录,以及历史的记录


通过git reflog查看到你对这个本地仓库做了哪些操作

标签:10,shell,tomcat,root,控制系统,git,版本,my
From: https://www.cnblogs.com/btcm409181423/p/18288758

相关文章