版本控制系统

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 参数,身份信息,会写入 ~/.gitconfiggit config --global user.name "lisa"
git config --global user.email "wowo40981423@163.com"
# 开启git命令的颜色支持
git config --global color.ui true查看配置文件
cat ~/.gitconfig查看当前机器的git身份配置信息
[root@web-7 ~/git-learn]#cat ~/.gitconfig
[user]name = wenjieemail = wenjie01@163.com
[color]ui = true列出git设置
[root@web-7 ~/git-learn]#git config --list
user.name=wenjie
user.email=wenjie01@163.com
color.ui=true

git身份设置命令集合

yum install git -y  安装gitgit --version  查看git版本git config --system --list 查看系统所有linux用户的通用配置,此命令检查/etc/gitconfiggit 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 "yc_uuu@163.com"  配置当前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.sh3. 通过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.sh3提交版本了,提交第一个版本
[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.sh4查看版本记录日志
[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 <yc_uuu@163.com>
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 <yc_uuu@163.com>
Date:   Fri Jul 15 19:03:27 2022 +0800heheheh 那我走?commit 3b4420b805b297239d9b3adc8c8605e593cab5d9
Author: pyyu <yc_uuu@163.com>
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.javagit 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查看到你对这个本地仓库做了哪些操作

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/739861.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

2024-07-07 如何把ipad当作windows副屏使用 ==》 通过软件dute display和数据线连接

windows:进入dutedisplay官网https://www.duetdisplay.com/zh#download,下载并安装 ipad:在苹果应用商店搜索dutedisplay,选中并下载注意:你需要注册一个dutedisplay账号,才能登录该软件,它是付费的,so,我看到付费我就放弃了。 如果,你给钱了,那么,接下来我也不知道…

AtCoder Beginner Contest 361

AtCoder Beginner Contest 361 A - Insert给定一个长度为\(N\)的序列\(A\),现在希望将数字\(X\)插入到序列的第\(K\)个数字后面,变成一个新的序列\(B\)。输出序列\(B\)。 \(K,N,A_i,X\le 100\)模拟题。先读入\(N,K,X\)。接着在读入\(A\)的过程中一遍读入一遍输出,如果读到了…

2024暑假第一周总结

JAVA开发环境搭建和HelloWorld编译 1、JDK安装(java开发环境安装) 更改环境变量 Path环境变量 Path环境变量用于记住程序路径,方面在命令行窗口的任意目录启动程序 老版本的jdk需要进行配置环境变量,将jdk和bin包路径复制,新建path路径 Java_home环境变量 告诉操作系统JDK…

前端取唯一标识 UUID

// 使用工具 fingerprintjs 可以简单取到UUID1 <!DOCTYPE html>2 <html lang="en">3 4 <head>5 <meta charset="UTF-8">6 <meta http-equiv="X-UA-Compatible" content="IE=edge">7 <meta nam…

srpingboot 自定义 start

自动配置工程绑定配置文件,上逼格的 start 都支持自定义配置,我们也装像点~~ @ConfigurationProperties("cyrus.hello") public class CyrusHelloProperties {// 绑定配置文件 cyrus.hello.username 属性private String username;public String getUsername() {re…

Spring 配置文件加密

前文 在某些场景下,使用 Spring 作为开发组件时,不可避免地需要使用到配置文件,然而,对于配置文件中的某些敏感数据(如密码等信息字段),如果使用明文的方式,则可能在一定程度上导致信息泄露。为此,需要一种有效的方式来对这些字段进行加密处理,当前主流的一种加密方式…

博客搭建-图床篇

我们的博客难免少不了图片,图片管理是一个不小的难题。我们的博客难免少不了图片,图片管理是一个不小的难题。如果我们将图片全部放到我们自己的服务器上,那么带宽就基本上会被图片所占满了,这会导致网站加载很慢(特别是图片加载很慢)。 ‍ 什么是图床 为了解决图片的问题…

FPGA以太网学习-RGMII与GMII

以太网口都叫RJ45接口,从功能角度说,网口只是信号连接,本身没有通信能力。PHY(物理层),这边需要一个芯片,将并行的以太网数据到符合以太网物理层链路数据传输格式的电平信号转换。 上图PHY右边是经过编码后的串行数据信号,左侧是提供多种并行信号。网络变压器连接串行信…

网络通信系统的voronoi图显示与能耗分析matlab仿真

1.程序功能描述两层基站(BS)组成整个通讯网络,第 1 层为 Macro 基站记为 ,第 2 层为 Micro 基站记为 ,均服从泊松分布,相互独立,在坐标为 1010km 的面积内、按照泊松分布随机生成若干个点(随机抛洒两遍 nodes,两层叠加起来)。然后画成 voronoi 图: 也就是在相邻两个…

Django详细笔记

django 学习 特点快速开发 安全性高 可伸缩性强URL 组成部分 URL: 同意资源定位符 一个URL由以下几部分组成 scheme://host:port/path/?query-string=xxx#anchorscheme: 代表的是访问的协议,一般为http或https协议 host: 主机名,域名 port: 端口 http 默认:80端口 …

关于虚拟机的使用

1、从网上下载了Centos7 2024年CentOS镜像下载地址,包括CentOS官网、国内镜像下载,超详细教学,小白也能学会。-CSDN博客 2、通过VMware添加了该iso文件,打开虚拟机之后安装该系统就可以了 3、进入之后我们需要进行软件安装、安装位置、KDUMP、网络和主机名的修改操作其中,…

LSTUR论文阅读笔记

Neural News Recommendation with Long- and Short-term User Representations论文阅读笔记 这个同样是一篇很老但是比较经典的文章,这里来读一下 Abstract 存在的问题: ​ 用户通常既有长期偏好,也有短期兴趣。然而,现有的新闻推荐方法通常只学习用户的单一表征,这可能是…