
🔥艾莉丝努力练剑:个人主页
❄专栏传送门:《C语言》、《数据结构与算法》、C/C++干货分享&学习过程记录、Linux操作系统编程详解、笔试/面试常见算法:从基础到进阶、测试开发要点全知道
⭐️为天地立心,为生民立命,为往圣继绝学,为万世开太平
🎬艾莉丝的简介:

目录
[1 ~> 初始Git](#1 ~> 初始Git)
[2 ~> CentOs版本安装git](#2 ~> CentOs版本安装git)
[2.1 指令](#2.1 指令)
[2.2 最佳实践](#2.2 最佳实践)
[3 ~> ubuntu版本安装git](#3 ~> ubuntu版本安装git)
[3.1 安装git](#3.1 安装git)
[3.2 查看git安装的版本](#3.2 查看git安装的版本)
[4 ~> 基本操作:创建本地仓库](#4 ~> 基本操作:创建本地仓库)
[4.1 创建](#4.1 创建)
[4.2 在当前目录下创建git本地仓库](#4.2 在当前目录下创建git本地仓库)
[4.3 查看目录内容](#4.3 查看目录内容)
[5 ~> 基本操作:配置本地仓库](#5 ~> 基本操作:配置本地仓库)
[5.1 指令](#5.1 指令)
[5.2 查看](#5.2 查看)
[5.3 最佳实践1:局部环境配置](#5.3 最佳实践1:局部环境配置)
[5.3.1 名字](#5.3.1 名字)
[5.3.2 邮箱](#5.3.2 邮箱)
[5.4 最佳实践2:全局环境配置](#5.4 最佳实践2:全局环境配置)
[5.5 最佳实践3:删除](#5.5 最佳实践3:删除)
[5.6 --global选项](#5.6 --global选项)
[6 ~> 基本操作:认识工作区、暂存区、版本区](#6 ~> 基本操作:认识工作区、暂存区、版本区)
[7 ~> 基本操作:添加文件](#7 ~> 基本操作:添加文件)
[7.1 场景1](#7.1 场景1)
[7.2 场景2](#7.2 场景2)
[8 ~> 基本操作:查看.git文件](#8 ~> 基本操作:查看.git文件)
[8.1 指令](#8.1 指令)
[8.2 图示](#8.2 图示)
[8.3 手记](#8.3 手记)
[8.4 学习思路](#8.4 学习思路)
[9 ~> 基本操作:修改文件](#9 ~> 基本操作:修改文件)
[10 ~> 基本操作:版本回退](#10 ~> 基本操作:版本回退)
[11 ~> 基本操作:撤销修改------情况一 / 二 / 三](#11 ~> 基本操作:撤销修改——情况一 / 二 / 三)
[11.1 情况一](#11.1 情况一)
[11.2 情况二](#11.2 情况二)
[11.3 情况三](#11.3 情况三)
[11.4 验证](#11.4 验证)
[12 ~> 基本操作:删除文件](#12 ~> 基本操作:删除文件)
艾莉丝的Gitee地址

1 ~> 初始Git

2 ~> CentOs版本安装git
2.1 指令
查看安装版本:git --verion
下载:(sudo) yum install git -y
卸载:(sudo) yum remove git -y
2.2 最佳实践
bash
// 查看安装版本
git --verion
// 下载
(sudo) yum install git -y
// 卸载
(sudo) yum remove git -y
这里博主因为已经安装过git了,所以就只演示一下【查看安装版本】的操作------

3 ~> ubuntu版本安装git
如果你的的平台是ubuntu,安装git相当简单,以ubuntu20.04为例------
bash
$ git
Command 'git' not found, but can be installed with:
sudo apt install git
3.1 安装git
bash
$sudo apt-get install git -y
3.2 查看git安装的版本
bash
$ git --version
4 ~> 基本操作:创建本地仓库
4.1 创建
bash
mkdir gitcode
4.2 在当前目录下创建git本地仓库
bash
git init
4.3 查看目录内容
bash
tree .git/
运行如下------
bash
[root@VM-4-17-centos dir]# mkdir gitcode
[root@VM-4-17-centos dir]# ls
gitcode test.c
[root@VM-4-17-centos dir]# git init
Initialized empty Git repository in /home/jqj/dir/.git/
[root@VM-4-17-centos dir]# ls
gitcode test.c
[root@VM-4-17-centos dir]# tree .git/
.git/
|-- branches
|-- config
|-- description
|-- HEAD
|-- hooks
| |-- applypatch-msg.sample
| |-- commit-msg.sample
| |-- post-update.sample
| |-- pre-applypatch.sample
| |-- pre-commit.sample
| |-- prepare-commit-msg.sample
| |-- pre-push.sample
| |-- pre-rebase.sample
| `-- update.sample
|-- info
| `-- exclude
|-- objects
| |-- info
| `-- pack
`-- refs
|-- heads
`-- tags
9 directories, 13 files
5 ~> 基本操作:配置本地仓库
5.1 指令
bash
git config user.name "[名字]"
git config --unset user.name
git config user.email "[email]"
git config --unset user.email
git config --global user.name "[名字]"
git config --global --unset user.name
git config --global user.email "[email]"
git config --global --unset user.email
5.2 查看
bash
git config -l
5.3 最佳实践1:局部环境配置
5.3.1 名字
bash
[root@VM-4-17-centos dir]# git config user.name "jqj"
[root@VM-4-17-centos dir]# git config -l
user.name=jqj
user.email=18106882575@163.com
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
user.name=jqj
5.3.2 邮箱
cpp
[root@VM-4-17-centos dir]# git config user.name "181xxxxxxxx@163.com"
[root@VM-4-17-centos dir]# git config -l
user.name=jqj
user.email=181xxxxxxxx@163.com
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
user.name=181xxxxxxxx@163.com
5.4 最佳实践2:全局环境配置
bash
[root@VM-4-17-centos dir]# git config --global user.name "[名字]"
[root@VM-4-17-centos dir]# git config --global user.email "[email]"
[root@VM-4-17-centos dir]# git config -l
user.name=[名字]
user.email=[email]
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
5.5 最佳实践3:删除

5.6 --global选项
一台服务器上可以创建多个本地仓库,加了--global选项,目的是在当前机器的所有git仓库生效。
6 ~> 基本操作:认识工作区、暂存区、版本区

7 ~> 基本操作:添加文件

7.1 场景1


bash
[jqj@VM-4-17-centos gitcode]$ touch file1 file2 file3
[jqj@VM-4-17-centos gitcode]$ ls
file1 file2 file3
[jqj@VM-4-17-centos gitcode]$ git add file "add 3 file"
fatal: pathspec 'file' did not match any files
[jqj@VM-4-17-centos gitcode]$ git add file1 file2 file3
[jqj@VM-4-17-centos gitcode]$ git commit -m "add 3 file"
7.2 场景2

8 ~> 基本操作:查看.git文件
8.1 指令
bash
cat .git/HFAD
ref refs/heads/master
cat .git/refs/heads/master // 对象
git cat -file -p [commit ID]
查看对象内容:cat -file。
8.2 图示

8.3 手记


8.4 学习思路
刚开始学习git的时候,进行一些操作,都要与.git目录中的结构变化对应着来看,有利于了解git目录细节流程。
9 ~> 基本操作:修改文件


10 ~> 基本操作:版本回退





11 ~> 基本操作:撤销修改------情况一 / 二 / 三
11.1 情况一

11.2 情况二

11.3 情况三


11.4 验证

12 ~> 基本操作:删除文件





以上就是文件删除的两种流程,**git rm [文件名]**更快捷。
Git:基本操作部分博主手记










结尾
创作过程中难免有所缺漏,如果uu们发现艾莉丝的文章哪里有所疏忽,望不吝赐教!感谢支持!
往期回顾:
本文为本专栏的开篇之作,因此暂时还没有【往期回顾】环节,后期会加入的。
结语:都看到这里啦!那请大佬不要忘记给博主来个"一键四连"哦!
🗡博主在这里放了一只小狗,大家看完了摸摸小狗放松一下吧!🗡
૮₍ ˶ ˊ ᴥ ˋ˶₎ა
