Git原理(01)
Git原理基本介绍
1. 代码仓库的初始化
新建文件夹作为本地仓库
1
2xiong@Surface-pro6 MINGW64 /c/Files/gitStudy
mkdir git-demo初始化本地代码仓库
1
2
3
4
5xiong@Surface-pro6 MINGW64 /c/Files/gitStudy
git init
Initialized empty Git repository in C:/Files/gitStudy/.git/
xiong@Surface-pro6 MINGW64 /c/Files/gitStudy (master)初始化后会多出 .git的隐藏文件夹
1
2
3
4
5
6
7xiong@Surface-pro6 MINGW64 /c/Files/gitStudy (master)
ls -la
total 16
drwxr-xr-x 1 xiong 197609 0 Aug 21 10:10 ./
drwxr-xr-x 1 xiong 197609 0 Aug 21 08:52 ../
drwxr-xr-x 1 xiong 197609 0 Aug 21 10:10 .git/
drwxr-xr-x 1 xiong 197609 0 Aug 21 08:55 git-demo/查看.git文件夹
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29xiong@Surface-pro6 MINGW64 /c/Files/gitStudy (master)
find .git
.git
.git/config
.git/description
.git/HEAD
.git/hooks
.git/hooks/applypatch-msg.sample
.git/hooks/commit-msg.sample
.git/hooks/fsmonitor-watchman.sample
.git/hooks/post-update.sample
.git/hooks/pre-applypatch.sample
.git/hooks/pre-commit.sample
.git/hooks/pre-merge-commit.sample
.git/hooks/pre-push.sample
.git/hooks/pre-rebase.sample
.git/hooks/pre-receive.sample
.git/hooks/prepare-commit-msg.sample
.git/hooks/push-to-checkout.sample
.git/hooks/update.sample
.git/info
.git/info/exclude
.git/objects
.git/objects/info
.git/objects/pack
.git/refs
.git/refs/heads
.git/refs/tags删除掉hooks目录下的.sample文件,便于查看
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18xiong@Surface-pro6 MINGW64 /c/Files/gitStudy (master)
rm -rf .git/hooks/*.sample
xiong@Surface-pro6 MINGW64 /c/Files/gitStudy (master)
find .git
.git
.git/config
.git/description
.git/HEAD
.git/hooks
.git/info
.git/info/exclude
.git/objects
.git/objects/info
.git/objects/pack
.git/refs
.git/refs/heads
.git/refs/tags
1.1 查看config文件
config是配置的意思,那么git config命令就是对git进行一些配置。而配置一般都是写在配置文件里面,git里面一共有3个配置文件
1.1.1 仓库级配置文件
方法1:
找到该文件,直接打开:该文件位于当前仓库下,路径.git/,文件名为config

这个配置中的设置只对当前所在仓库(C:/Files/gitStudy)有效,仓库级配置文件内容如下:

方法2:
通过命令查看项目配置(仓库级配置):git config --local -l
1 | xiong@Surface-pro6 MINGW64 /c/Files/gitStudy (master) |
1.1.2 全局级配置文件
方法1:
以win10个人的PC机为例,在用户目录下,其路径为:C:\Users\Administrator,文件名为 .gitconfig
全局级配置文件内容如下:


方法2:
通过命令查看全局级配置:git config --global -l
1 | xiong@Surface-pro6 MINGW64 /c/Files/gitStudy (master) |
1.1.3 系统级配置文件
方法1:
本地git的安装目录下,以我的git安装路径为例:C:\SoftWares\Git\etc,文件名为:gitconfig,内容如下:


方法2:
通过命令查看系统配置:git config –system -l
1 | xiong@Surface-pro6 MINGW64 /c/Files/gitStudy (master) |
对于git来说,配置文件的权重是仓库>全局>系统
查看当前生效的配置
命令:git config -l,这个时候会显示最终三个配置文件计算后的配置信息,如下:
1 | xiong@Surface-pro6 MINGW64 /c/Files/gitStudy (master) |
1.2 使用git config命令编辑配置文件
编辑的英文单词是什么,没错,edit
命令参数 –edit, 简写 -e
格式:git config [–local|–global|–system] -e
编辑仓库级的config,命令:git config –local -e,与–list参数不同的是,git config -e默认是编辑仓库级的配置文件。
编辑全局级的config,命令:git config –global -e
编辑系统级的config,命令:git config –system -e
注:执行这个命令的时候,git会用配置文件中设定的编辑器打开配置文件。
1.3 使用git config命令增加一个配置项
参数 –add
格式: git config [-local|-global|-system] –add section.key value(默认是添加在local配置中)
注意add后面的section,key,value一项都不能少,否则添加失败。比如我们执行:
git config --add cat.name tom
注意增加一项配置而不赋值 git config -add cat.age,或者单单增加一个section,git config -add cat1,不会成功。然后查看local中的配置:
1 | xiong@Surface-pro6 MINGW64 /c/Files/gitStudy (master) |
添加本地用户信息,用于提交时指向提交者
1 | xiong@Surface-pro6 MINGW64 /c/Files/gitStudy (master) |
1.4 使用git config命令获取一个配置项
有时候,我们并不需要查看所有配置的值,而是查看某个配置项的值,怎么做呢?
命令参数 -get
格式:git config [-local|-global|-system] -get section.key(默认是获取local配置中内容)
我们先往git配置中写入一个cat.name=tom的配置项,再使用git config -get cat.name看看得到的是什么
1 | xiong@Surface-pro6 MINGW64 /c/Files/gitStudy (master) |
结果就是local中的cat.name=tom,因此git config –get section.key 等价于
git config –local –get section.key
如果获取一个section不存在的key值,不会返回任何值
如果获取一个不存在的section的key值,则会报错
1 | xiong@Surface-pro6 MINGW64 /c/Files/gitStudy (master) |
1.5 使用git config命令删除一个配置项
命令参数 -unset
格式:git config [-local|-global|-system] -unset section.key
相信有了前两个命令的使用基础,大家举一反三就知道改怎么用了,来,我们试试删除local配置中的cat.name
1 | xiong@Surface-pro6 MINGW64 /c/Files/gitStudy (master) |
2. git add背后发什么了什么
在当前工作区(C:/Files/GitStudy)新建文件
1 | xiong@Surface-pro6 MINGW64 /c/Files/gitStudy (master) |
查看此时git状态
1 | xiong@Surface-pro6 MINGW64 /c/Files/gitStudy (master) |
如果需要git帮我们管理hello.txt文件,则需将当前文件从工作区添加到缓冲区
1 | xiong@Surface-pro6 MINGW64 /c/Files/gitStudy (master) |
为了方便观察,我们在window的cmd里使用tree命令(因为git bash不支持此命令,后续的文件树结构均是在windows里的cmd显示)查看.git当前的文件结构
1 | xiong@SURFACE-PRO6 C:\Files\gitStudy |
新增了 index文件,object文件夹下新增了8d文件夹,8d文件夹下新增了一串名为hash的objects文件,此处objects下新增的文件加以及文件,名字组合起来为一个SHA1值,这个值是由从工作区add到缓冲区的文件内容和文件类型进行哈希散列得到的(”blob %u\0” % len(date))
2.1 分析新增的objects对象
使用git cat-file 查看objects文件:
① -t SHA1值:查看该objects的类型(SHA1值一般去前6位就已足够。记得别忘了文件夹的那两位)
1 | xiong@Surface-pro6 MINGW64 /c/Files/gitStudy (master) |
blob文件:只存储文件内容,不存储文件名
验证:新建一个tmp.txt文件,内容与hello.txt一致,执行git add进行添加后,查看.git文件目录结构
1 | xiong@SURFACE-PRO6 C:\Files\gitStudy |
发现文件目录没有任何改变
② -p SHA1值:查看该objects的内容
1 | xiong@Surface-pro6 MINGW64 /c/Files/gitStudy (master) |
③ -s SHA1值:查看该objects对象的长度
1 | xiong@Surface-pro6 MINGW64 /c/Files/gitStudy (master) |
3. blob对象和SHA1哈希
3.1 Hash算法
把任意长度的输入通过散列算法变换成固定长度的输出
- MD5 128bit
- SHA1 160bit
- SHA256 256bit
- SHA512 512bit
- Hash在线计算、md5计算、sha1计算、sha256计算、sha512计算 - 1024Tools
3.2 还原git生成SHA1的过程
查看要生成文件的大小
1
2
3
4
5
6xiong@Surface-pro6 MINGW64 /c/Files/gitStudy (master)
ls -lh
total 2.0K
drwxr-xr-x 1 xiong 197609 0 Aug 21 08:55 git-demo/
-rw-r--r-- 1 xiong 197609 10 Aug 21 11:43 hello.txt
-rw-r--r-- 1 xiong 197609 10 Aug 21 12:15 tmp.txt此处选择计算 hello.txt 大小为10B
计算
1
2
3xiong@Surface-pro6 MINGW64 /c/Files/gitStudy (master)
echo -e "blob 10\0hello git"|shasum
8d0e41234f24b6da002d962a26c2495ea16a425f *-对于echo
-e enable interpretation of the following backslash escapes
启用以下反斜杠转义的解释
3.3 了解git通过压缩对文件进行管理
查看blob文件
1 | xiong@Surface-pro6 MINGW64 /c/Files/gitStudy (master) |
出现乱码的原因是:git在存储文件时对文件内容进行了压缩
对比blob文件与原始文件
1 | xiong@Surface-pro6 MINGW64 /c/Files/gitStudy (master) |
blob文件大小为26B,原始文件大小为10B(因为源文件过小,导致压缩后的文件在包含压缩信息后反而增大,如果换为大文件,则能够看出明显效果)
4. 工作区和索引区

Working directory:工作区
Staging Area(index):索引区 —> 文件内容存在blob里,文件名存储在index里
初始化一个新的代码仓库进行实验
1 | xiong@Surface-pro6 MINGW64 /c/Files/git-demo |
文件树
1 | xiong@SURFACE-PRO6 C:\Files\git-demo |
列出当前在索引区里的内容
git ls-files:列出索引区里的内容
1 | xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master) |
git ls-files -s:列出索引区里文件的具体内容
1 | xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master) |
10064:标识权限
e2129701f1a4d54dc44f03c93bca0a2aec7c5449:blob对象
4.1 新建file2.txt,不进行提交,查看当前状态
1 | xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master) |
查看工作区
1
2
3xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
ls
file1.txt file2.txt查看索引区
1
2
3xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git ls-files
file1.txt查看git状态
1
2
3
4
5
6
7
8
9
10
11
12
13
14xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: file1.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
file2.txt**Untracked files:**文件的一种状态,在工作区新建的文件,但是没有添加到索引区
4.2 将file2.xtx添加到索引区后再进行查看
1 | xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master) |
查看当前objects目录
1 | xiong@SURFACE-PRO6 C:\Files\git-demo |
查看索引区
1 | xiong@SURFACE-PRO6 C:\Files\git-demo |
4.3 修改file1.txt后再进行查看
1 | xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master) |
在末尾添加一个”.”
查看工作区
1
2
3
4xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
ls
file1.txt file2.txt查看索引区
1
2
3
4
5xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git ls-files
file1.txt
file2.txt查看git状态
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: file1.txt
new file: file2.txt
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: file1.txtmodified:文件的另一种状态。索引区存在file1.txt,但是通过对比发现,此文件在工作区里的内容和在索引区里的内容不一致,判定此文件被修改了
4.4 将修改后的file1.txt进行提交
提交前索引区里的文件
1
2
3
4xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git ls-files -s
100644 e2129701f1a4d54dc44f03c93bca0a2aec7c5449 0 file1.txt
100644 6c493ff740f9380390d5c9ddef4af18697ac9375 0 file2.txt提交后索引区里的文件
1
2
3
4
5
6
7
8
9
10xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git add file1.txt
warning: LF will be replaced by CRLF in file1.txt.
The file will have its original line endings in your working directory
xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git ls-files -s
100644 ca5a43e53e012b6fd3b2a8a06ebb6c2ee24a24e5 0 file1.txt
100644 6c493ff740f9380390d5c9ddef4af18697ac9375 0 file2.txt
对比前后发现此时的file1.txt文件的blob发生了变化
查看objects目录
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16xiong@SURFACE-PRO6 C:\Files\git-demo
tree .git/objects /f
卷 Local Disk 的文件夹 PATH 列表
卷序列号为 C0000100 F296:2801
C:\FILES\GIT-DEMO\.GIT\OBJECTS
├─6c
│ 493ff740f9380390d5c9ddef4af18697ac9375
│
├─ca
│ 5a43e53e012b6fd3b2a8a06ebb6c2ee24a24e5 #file1.txt新
│
├─e2
│ 129701f1a4d54dc44f03c93bca0a2aec7c5449 #file1.txt旧
│
├─info
└─pack
5. git commit背后发什么了什么

5.1 未进行commit文件的内容和状态
1 | xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master) |
此时工作区和索引区状态一致
5.2 commit一次后各文件的状态
1 | xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master) |
5.2.1 objects中新增文件
1 | xiong@SURFACE-PRO6 C:\Files\git-demo |
根据commit生成的SHA1,查看新增文件
查看文件类型
1
2
3xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git cat-file -t 8a44
commit文件为commit类型
查看文件内容
1
2
3
4
5
6
7xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git cat-file -p 8a44
tree 29d3f358addb2b6e16ebfb981716fa75cc562ee7
author xiongzhuo <xiongzhuo@outlook.com> 1629531426 +0800
committer xiongzhuo <xiongzhuo@outlook.com> 1629531426 +0800
1st commit包含了一个tree对象和提交者的信息,以及提交时的备注
查看commit文件里tree的类型
1
2
3
4xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git cat-file -t 29d3f
tree查看commit文件里tree的内容
1
2
3
4
5xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git cat-file -p 29d3f
100644 blob ca5a43e53e012b6fd3b2a8a06ebb6c2ee24a24e5 file1.txt
100644 blob 6c493ff740f9380390d5c9ddef4af18697ac9375 file2.txttree里记录了当前提交的内容
5.2.2 refs中新增文件
1 | xiong@SURFACE-PRO6 C:\Files\git-demo |
查看新增文件内容
1 | xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master) |
master里存着最近一次commit的SHA1值
关联:查看.git里的HEAD文件
1 | xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master) |
HEAD指向当前工作的分支
5.2.3 commit一次后代码仓库的状态

5.3 commit二次后各文件的状态
修改file2.txt里的内容
1 | xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master) |
在末尾添加”.”
查看当前git status状态
1 | xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master) |
跟踪到了被修改的file2.txt
将修改后的文件添加到索引区
1
2
3
4
5xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git add file2.txt
warning: LF will be replaced by CRLF in file2.txt.
The file will have its original line endings in your working directory查看objects中的文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25xiong@SURFACE-PRO6 C:\Files\git-demo
tree .git/objects /f
卷 Local Disk 的文件夹 PATH 列表
卷序列号为 C0000100 F296:2801
C:\FILES\GIT-DEMO\.GIT\OBJECTS
├─29
│ d3f358addb2b6e16ebfb981716fa75cc562ee7
│
├─6c
│ 493ff740f9380390d5c9ddef4af18697ac9375
│
├─8a
│ 44e8c0e81d4766b22777a61f3233d8b14497cc
│
├─98
│ 87c1a1fdc70e53d47d73b5764a65c889704ef3 #新增blob
│
├─ca
│ 5a43e53e012b6fd3b2a8a06ebb6c2ee24a24e5
│
├─e2
│ 129701f1a4d54dc44f03c93bca0a2aec7c5449
│
├─info
└─pack查看当前索引区中文件
1
2
3
4xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git ls-files -s
100644 ca5a43e53e012b6fd3b2a8a06ebb6c2ee24a24e5 0 file1.txt
100644 9887c1a1fdc70e53d47d73b5764a65c889704ef3 0 file2.txtfile2.txt的blob对象更新
将更新进行提交
1 | xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master) |
查看当前objects中的文件
1 | xiong@SURFACE-PRO6 C:\Files\git-demo |
查看当前commit对象中的内容
1
2
3
4
5
6
7
8
9xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git cat-file -p 192806
tree 876af0020e37f45ec09c802d96d7120b2302075f
parent 8a44e8c0e81d4766b22777a61f3233d8b14497cc
author xiongzhuo <xiongzhuo@outlook.com> 1629533646 +0800
committer xiongzhuo <xiongzhuo@outlook.com> 1629533646 +0800
2nd commitparent指向的是上一个commit
查看当前commit中tree的内容
1
2
3
4
5xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git cat-file -p 876af0
100644 blob ca5a43e53e012b6fd3b2a8a06ebb6c2ee24a24e5 file1.txt
100644 blob 9887c1a1fdc70e53d47d73b5764a65c889704ef3 file2.txtfile2.txt的blob进行了更新
5.3.3 commit二次后代码仓库的状态

5.4 commit文件夹
新建文件夹
1 | xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master) |
1 | xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master) |
对于空文件夹,git不算任何改变
进入到新文件夹里,新建文件后git能够将其识别
1 | xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master) |
将未跟踪的文件添加到索引区
1 | xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master) |
查看索引区内容
1 | xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master) |
查看objects文件夹里的内容
1 | xiong@SURFACE-PRO6 C:\Files\git-demo |
commit更新的内容
1 | xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master) |
查看objects文件的内容
1 | xiong@SURFACE-PRO6 C:\Files\git-demo |
查看commit内容
1
2
3
4
5
6
7
8
9xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git cat-file -p a1431a
tree 46fcafbbc3e0ba215d6b9924a20a0cb3b107423f
parent 1928061d327bfa64a0a6ce3f4faa029b8c1ce776
author xiongzhuo <xiongzhuo@outlook.com> 1629537005 +0800
committer xiongzhuo <xiongzhuo@outlook.com> 1629537005 +0800
3rd commit查看commit里tree对象内容
1
2
3
4
5
6xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git cat-file -p 46fcaf
100644 blob ca5a43e53e012b6fd3b2a8a06ebb6c2ee24a24e5 file1.txt
100644 blob 9887c1a1fdc70e53d47d73b5764a65c889704ef3 file2.txt
040000 tree e3cfebfb440e2af91732e71deda277030d7182e9 folder1当前tree包含另一个与文件夹同名的tree
查看commit里tree对象里tree对象的内容
1
2
3
4xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git cat-file -p e3cfeb
100644 blob 89a53edddc5f8fbc09bc500a2a807750e9673c08 file3.txt当前tree里包含了file3.txt的blob对象
5.4.1 commit文件夹后代码仓库的状态

6. 文件的状态

7. Branch和HEAD
Branch:分支,被命名为指针去指向commits
HEAD:是一个特殊的指针,指向当前工作的分支,且总是指向最近一次提交

验证
查看HEAD文件的内容:指向refs/heads/master
1
2
3xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
cat .git/HEAD
ref: refs/heads/master查看master内容
1
2
3xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
cat .git/refs/heads/master
a1431ae9fc3ef4f2ddd35c6a44349b69a5bd2f8b查看master内容所指文件的类型
1
2
3xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git cat-file -t a1431a
commit查看提交历史:HEAD指向master分支,且指向最新一次提交
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git log
commit a1431ae9fc3ef4f2ddd35c6a44349b69a5bd2f8b (HEAD -> master)
Author: xiongzhuo <xiongzhuo@outlook.com>
Date: Sat Aug 21 17:10:05 2021 +0800
3rd commit
commit 1928061d327bfa64a0a6ce3f4faa029b8c1ce776
Author: xiongzhuo <xiongzhuo@outlook.com>
Date: Sat Aug 21 16:14:06 2021 +0800
2nd commit
commit 8a44e8c0e81d4766b22777a61f3233d8b14497cc
Author: xiongzhuo <xiongzhuo@outlook.com>
Date: Sat Aug 21 15:37:06 2021 +0800
1st commit
7.1 Branch的创建和使用
- git branch:列举出拥有的分支
- git branch
:以branch_name为名创建分支,如果已有同名分支,则返回失败 - git branch -D
:删除分支,不能删除当前工作的分支或不存在的分支 - git checkout:更改当前的工作分支
7.1.1 查看分支
1 | xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master) |
*master:表示当前所在分支是master
7.1.2 创建分支
1 | xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master) |
查看提交历史
1 | xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master) |
HEAD -> master, dev:HEAD当前指向的是master,而此时新建的分支dev恰好指向的也是a1431a这次提交,所以显示成这样
1 | xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master) |
分支存在.git/refs/heads/目录下
1 | xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master) |
7.1.3 切换分支
1 | xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master) |
切换分支
1
2
3xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git checkout dev
Switched to branch 'dev'当前所处分支
查看当前所处分支
1
2
3
4xiong@Surface-pro6 MINGW64 /c/Files/git-demo (dev)
git branch
* dev
master查看HEAD指向
1
2
3xiong@Surface-pro6 MINGW64 /c/Files/git-demo (dev)
cat .git/HEAD
ref: refs/heads/dev查看提交记录
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20xiong@Surface-pro6 MINGW64 /c/Files/git-demo (dev)
git log
commit a1431ae9fc3ef4f2ddd35c6a44349b69a5bd2f8b (HEAD -> dev, master)
Author: xiongzhuo <xiongzhuo@outlook.com>
Date: Sat Aug 21 17:10:05 2021 +0800
3rd commit
commit 1928061d327bfa64a0a6ce3f4faa029b8c1ce776
Author: xiongzhuo <xiongzhuo@outlook.com>
Date: Sat Aug 21 16:14:06 2021 +0800
2nd commit
commit 8a44e8c0e81d4766b22777a61f3233d8b14497cc
Author: xiongzhuo <xiongzhuo@outlook.com>
Date: Sat Aug 21 15:37:06 2021 +0800
1st commit
在dev分支上进行操作
新建文件
1
2
3
4
5
6xiong@Surface-pro6 MINGW64 /c/Files/git-demo (dev)
echo "dev" > dev.txt
xiong@Surface-pro6 MINGW64 /c/Files/git-demo (dev)
ls
dev.txt file1.txt file2.txt folder1/将工作区的文件添加到索引区
1
2
3
4xiong@Surface-pro6 MINGW64 /c/Files/git-demo (dev)
git add dev.txt
warning: LF will be replaced by CRLF in dev.txt.
The file will have its original line endings in your working directory提交文件
1
2
3
4
5xiong@Surface-pro6 MINGW64 /c/Files/git-demo (dev)
git commit -m "1st commit from dev branch"
[dev 939dc9f] 1st commit from dev branch
1 file changed, 1 insertion(+)
create mode 100644 dev.txt查看提交记录
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26xiong@Surface-pro6 MINGW64 /c/Files/git-demo (dev)
git log
commit 939dc9f4fbb92d5bdcff9952f6de1f432fed1b3a (HEAD -> dev)
Author: xiongzhuo <xiongzhuo@outlook.com>
Date: Sat Aug 21 20:34:48 2021 +0800
1st commit from dev branch
commit a1431ae9fc3ef4f2ddd35c6a44349b69a5bd2f8b (master)
Author: xiongzhuo <xiongzhuo@outlook.com>
Date: Sat Aug 21 17:10:05 2021 +0800
3rd commit
commit 1928061d327bfa64a0a6ce3f4faa029b8c1ce776
Author: xiongzhuo <xiongzhuo@outlook.com>
Date: Sat Aug 21 16:14:06 2021 +0800
2nd commit
commit 8a44e8c0e81d4766b22777a61f3233d8b14497cc
Author: xiongzhuo <xiongzhuo@outlook.com>
Date: Sat Aug 21 15:37:06 2021 +0800
1st commit
7.1.4 删除分支
删除失败情况:不能删除当前分支
1 | xiong@Surface-pro6 MINGW64 /c/Files/git-demo (dev) |
git branch –delete dev
1
2
3
4xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git branch --delete dev
error: The branch 'dev' is not fully merged.
If you are sure you want to delete it, run 'git branch -D dev'.在使用–delete (-d)删除时,系统会有提示消息,删除分支时建议使用-d
git brnach -D dev
1
2
3xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git branch -D dev
Deleted branch dev (was 939dc9f).删除分支后,该分支上的文件还存在
查看939dc9f
1
2
3xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git cat-file -t 939dc9f
commit查看该文件内容
1
2
3
4
5
6
7
8
9xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git cat-file -p 939dc9f
tree b48a27332ca027db625a0601ab1c6957fe4f5cc8
parent a1431ae9fc3ef4f2ddd35c6a44349b69a5bd2f8b
author xiongzhuo <xiongzhuo@outlook.com> 1629549288 +0800
committer xiongzhuo <xiongzhuo@outlook.com> 1629549288 +0800
1st commit from dev branch查看文件中tree的内容
1
2
3
4
5
6xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git cat-file -p b48a27
100644 blob 38f8e886e1a6d733aa9bfa7282568f83c133ecd6 dev.txt
100644 blob ca5a43e53e012b6fd3b2a8a06ebb6c2ee24a24e5 file1.txt
100644 blob 9887c1a1fdc70e53d47d73b5764a65c889704ef3 file2.txt
040000 tree e3cfebfb440e2af91732e71deda277030d7182e9 folder1查看dev.txt的内容
1
2
3xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git cat-file -p 38f8e8
dev通过此四步操作,任然能查看到被删除分支上的内容。这样遗留下来的对象为垃圾对象
在git 进行的删除,它实际上只是删除了指向某个commit的指针,这个commit没有被删除
8. checkout特定的commit
可以通过chekout切换到特定的commit上
查看commit历史,切换到指定分支
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git log
commit a1431ae9fc3ef4f2ddd35c6a44349b69a5bd2f8b (HEAD -> master)
Author: xiongzhuo <xiongzhuo@outlook.com>
Date: Sat Aug 21 17:10:05 2021 +0800
3rd commit
commit 1928061d327bfa64a0a6ce3f4faa029b8c1ce776
Author: xiongzhuo <xiongzhuo@outlook.com>
Date: Sat Aug 21 16:14:06 2021 +0800
2nd commit
commit 8a44e8c0e81d4766b22777a61f3233d8b14497cc
Author: xiongzhuo <xiongzhuo@outlook.com>
Date: Sat Aug 21 15:37:06 2021 +0800
1st commit1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git checkout 192806
Note: switching to '192806'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:
git switch -c <new-branch-name>
Or undo this operation with:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false
HEAD is now at 1928061 2nd commit
xiong@Surface-pro6 MINGW64 /c/Files/git-demo ((1928061...))
git log
commit 1928061d327bfa64a0a6ce3f4faa029b8c1ce776 (HEAD)
Author: xiongzhuo <xiongzhuo@outlook.com>
Date: Sat Aug 21 16:14:06 2021 +0800
2nd commit
commit 8a44e8c0e81d4766b22777a61f3233d8b14497cc
Author: xiongzhuo <xiongzhuo@outlook.com>
Date: Sat Aug 21 15:37:06 2021 +0800
1st commit
1
2
3
4
5
6
7xiong@Surface-pro6 MINGW64 /c/Files/git-demo ((1928061...))
git checkout 8a44e8
Previous HEAD position was 1928061 2nd commit
HEAD is now at 8a44e8c 1st commit
xiong@Surface-pro6 MINGW64 /c/Files/git-demo ((8a44e8c...))
可以通过
git checkout -b 分支名在当前commit创建分支1
2
3xiong@Surface-pro6 MINGW64 /c/Files/git-demo ((8a44e8c...))
git checkout -b tmp
Switched to a new branch 'tmp'1
2
3
4
5
6
7
8
9
10
11xiong@Surface-pro6 MINGW64 /c/Files/git-demo (tmp)
git log
commit 8a44e8c0e81d4766b22777a61f3233d8b14497cc (HEAD -> tmp)
Author: xiongzhuo <xiongzhuo@outlook.com>
Date: Sat Aug 21 15:37:06 2021 +0800
1st commit
xiong@Surface-pro6 MINGW64 /c/Files/git-demo (tmp)
cat .git/HEAD
ref: refs/heads/tmp通过git log发现当前指向并未变,只是分支名发生了变化

8.1 使用场景
分支在未合并时就被删除,可以通过checkout + git reflog进行恢复
git log是显示当前的HEAD和它的祖先的,递归是沿着当前指针的父亲,父亲的父亲,……,这样的原则。git reflog根本不遍历HEAD的祖先。它是HEAD所指向的一个顺序的提交列表:它的undo历史。reflog并不是repo(仓库)的一部分,它单独存储,而且不包含在pushes,fetches或者clones里面,它纯属是本地的。reflog可以很好地帮助你恢复你误操作的数据,例如你错误地reset了一个旧的提交,或者rebase,……,这个时候你可以使用reflog去查看在误操作之前的信息,并且使用git reset --hard去恢复之前的状态。
以之前删除的dev分支为例
切换到master分支
1
2
3xiong@Surface-pro6 MINGW64 /c/Files/git-demo (tmp)
git checkout master
Switched to branch 'master'使用
git reflog查看HEAD所指向的顺序提交的列表1
2
3
4
5
6
7
8
9
10
11
12xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git reflog
a1431ae (HEAD -> master) HEAD@{0}: checkout: moving from tmp to master
8a44e8c (tmp) HEAD@{1}: checkout: moving from 8a44e8c0e81d4766b22777a61f3233d8b14497cc to tmp
8a44e8c (tmp) HEAD@{2}: checkout: moving from 1928061d327bfa64a0a6ce3f4faa029b8c1ce776 to 8a44e8
1928061 HEAD@{3}: checkout: moving from master to 192806
a1431ae (HEAD -> master) HEAD@{4}: checkout: moving from dev to master
939dc9f HEAD@{5}: commit: 1st commit from dev branch
a1431ae (HEAD -> master) HEAD@{6}: checkout: moving from master to dev
a1431ae (HEAD -> master) HEAD@{7}: commit: 3rd commit
1928061 HEAD@{8}: commit: 2nd commit
8a44e8c (tmp) HEAD@{9}: commit (initial): 1st commit找到
939dc9f HEAD@{5}: commit: 1st commit from dev branch使用checkout 切换到所找到的commit,进入到
'detached HEAD'模式1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git checkout 939dc9f
Note: switching to '939dc9f'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:
git switch -c <new-branch-name>
Or undo this operation with:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false
HEAD is now at 939dc9f 1st commit from dev branch
xiong@Surface-pro6 MINGW64 /c/Files/git-demo ((939dc9f...))
ls
dev.txt file1.txt file2.txt folder1/切换到该commit以后,dev.txt文件再次出现
在此处建立新的分支进行切换,
git switch -c <new-branch-name>是新版提供的命令,在此处用git checkout -b dev与之等效1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30xiong@Surface-pro6 MINGW64 /c/Files/git-demo ((939dc9f...))
git switch -c dev
Switched to a new branch 'dev'
xiong@Surface-pro6 MINGW64 /c/Files/git-demo (dev)
git log
commit 939dc9f4fbb92d5bdcff9952f6de1f432fed1b3a (HEAD -> dev)
Author: xiongzhuo <xiongzhuo@outlook.com>
Date: Sat Aug 21 20:34:48 2021 +0800
1st commit from dev branch
commit a1431ae9fc3ef4f2ddd35c6a44349b69a5bd2f8b (master)
Author: xiongzhuo <xiongzhuo@outlook.com>
Date: Sat Aug 21 17:10:05 2021 +0800
3rd commit
commit 1928061d327bfa64a0a6ce3f4faa029b8c1ce776
Author: xiongzhuo <xiongzhuo@outlook.com>
Date: Sat Aug 21 16:14:06 2021 +0800
2nd commit
commit 8a44e8c0e81d4766b22777a61f3233d8b14497cc (tmp)
Author: xiongzhuo <xiongzhuo@outlook.com>
Date: Sat Aug 21 15:37:06 2021 +0800
1st commit
9. git diff命令
用来比较文件间的区别
新建测试文件README.txt,将其从工作区添加到索引区
1 | xiong@Surface-pro6 MINGW64 /c/Files/git-demo (dev) |
修改工作区中的README.txt,比较工作区与索引区README.txt的区别
①使用Sublime Merge工具可以检测到文件被修改了,绿色为修改部分

②使用
git diff命令进行查询1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17xiong@Surface-pro6 MINGW64 /c/Files/git-demo (dev)
git diff
diff --git a/README.txt b/README.txt
index eac2114..ff06760 100644
--- a/README.txt
+++ b/README.txt
@@ -92,4 +92,6 @@ git add . # 添加本地代码
git commit -m "add local source" # 提交本地代码
git pull origin master # 下载远程代码
git merge master # 合并master分支
-git push -u origin master # 上传代码
\ No newline at end of file
+git push -u origin master # 上传代码
+
+#添加信息
\ No newline at end of filediff --git a/README.txt b/README.txt:显示只有README.txt文件有区别;index eac2114..ff06760 100644:对比的是index(索引区里)eac2114(当前索引区文件的blob对象),ff06760是工作区文件的SHA1值
--- a/README.txt:代表索引区文件+++ b/README.txt:代表工作区文件@@ -92,4 +92,6 @@ git add .:不同之处位于,索引区从92行开始往后数4行和工作区从92行开始往后数6行通过
git diff --cached对比索引区与代码仓库的不同1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107xiong@Surface-pro6 MINGW64 /c/Files/git-demo (dev)
git diff --cached
diff --git a/README.txt b/README.txt
new file mode 100644
index 0000000..eac2114
--- /dev/null
+++ b/README.txt
@@ -0,0 +1,95 @@
+#常用命令
+git remote add origin git@github.com:yeszao/dofiler.git # 配置远程git版本
库
+git pull origin master # 下载代码及快速合并
+git push origin master # 上传代码及快速合并
+git fetch origin # 从远程库获取代码
+git branch # 显示所有分支
+git checkout master # 切换到master分支
+git checkout -b dev # 创建并切换到dev
分支
+git commit -m "first version" # 提交
+git status # 查看状态
+git log # 查看提交历史
+git config --global core.editor vim # 设置默认编辑器为vim(git默认用nano)
+git config core.ignorecase false # 设置大小写敏感
+git config --global user.name "YOUR NAME" # 设置用户名
+git config --global user.email "YOUR EMAIL ADDRESS" # 设置邮箱
+
+#别名
+git config --global alias.br="branch" # 创建/查看本地分支
+git config --global alias.co="checkout" # 切换分支
+git config --global alias.cb="checkout -b" # 创建并切换到新分支
+git config --global alias.cm="commit -m" # 提交
+git config --global alias.st="status" # 查看状态
+git config --global alias.pullm="pull origin master" # 拉取分支
+git config --global alias.pushm="push origin master" # 提交分支
+git config --global alias.log="git log --oneline --graph --decorate --color=always" # 单行、分颜色显示记录
+git config --global alias.logg="git log --graph --all --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(bold white)— %an%C(reset)%C(bold yellow)%d%C(reset)' --abbrev-commit --date=relative" # 复杂显示
+
+#创建版本库
+git clone <url> # 克隆远程版本库
+git init # 初始化本地版本库
+
+#修改和提交
+git status # 查看状态
+git diff # 查看变更内容
+git add . # 跟踪所有改动过的文件
+git add <file> # 跟踪指定的文件
+git mv <old> <new> # 文件改名
+git rm <file> # 删除文件
+git rm --cached <file> # 停止跟踪文件但不删除
+git commit -m “commit message” # 提交所有更新过的文件
+git commit --amend # 修改最后一次提交
+
+#查看历史
+git log # 查看提交历史
+git log -p <file> # 查看指定文件的提交历史
+git blame <file> # 以列表方式查看指定文件的提交历史
+
+#撤销
+git reset --hard HEAD # 撤消工作目录中所有未提交文件的修改内容
+git reset --hard <version> # 撤销到某个特定版本
+git checkout HEAD <file> # 撤消指定的未提交文件的修改内容
+git checkout --<file> # 同上一个命令
+git revert <commit> # 撤消指定的提交分支与标签
+
+#分支与标签
+git branch # 显示所有本地分支
+git checkout <branch/tag> # 切换到指定分支或标签
+git branch <new-branch> # 创建新分支
+git branch -d <branch> # 删除本地分支
+git tag # 列出所有本地标签
+git tag <tag-name> # 基于最新提交创建标签
+git tag -a "v1.0" -m "一些说明" # -a指定标签名称,-m指定标签说明
+git tag -d <tag-name> # 删除标签
+git checkout dev # 合并特定的commit到dev分支上
+git cherry-pick 62ecb3
+
+#合并与衍合
+git merge <branch> # 合并指定分支到当前分支
+git merge --abort # 取消当前合并,重建合并前状态
+git merge dev -Xtheirs # 以合并dev分支到当前分支,有冲突则以dev分支为准
+git rebase <branch> # 衍合指定分支到当前分支
+
+#远程操作
+git remote -v # 查看远程版本库信息
+git remote show <remote> # 查看指定远程版本库信息
+git remote add <remote> <url> # 添加远程版本库
+git remote remove <remote> # 删除指定的远程版本库
+git fetch <remote> # 从远程库获取代码
+git pull <remote> <branch> # 下载代码及快速合并
+git push <remote> <branch> # 上传代码及快速合并
+git push <remote> :<branch/tag-name> # 删除远程分支或标签
+git push --tags # 上传所有标签
+
+#打包
+git archive --format=zip --output ../file.zip master # 将master分支打包成file.zip文件,保存在上一级目录
+git archive --format=zip --output ../v1.2.zip v1.2 # 打包v1.2标签的文件,保存在上一级目录v1.2.zip文件中
+git archive --format=zip v1.2 > ../v1.2.zip # 作用同上一条命令
+
+#远程与本地合并
+git init # 初始化本地代码仓
+git add . # 添加本地代码
+git commit -m "add local source" # 提交本地代码
+git pull origin master # 下载远程代码
+git merge master # 合并master分支
+git push -u origin master # 上传代码
\ No newline at end of file由于未将文件提交到仓库,所以仓库将文件里的内容全部作为新增内容
将修改后的文件先添加到索引区,再从索引区添加到代码仓库
1
2
3
4
5
6
7
8
9xiong@Surface-pro6 MINGW64 /c/Files/git-demo (dev)
git add README.txt
xiong@Surface-pro6 MINGW64 /c/Files/git-demo (dev)
git commit -m "2nd commit from dev"
[dev 116e5dd] 2nd commit from dev
1 file changed, 97 insertions(+)
create mode 100644 README.txt
10. 远程仓库的添加


在此演示将本地仓库以httpsh的方式push到远程仓库

1 | git remote add origin https://github.com/xiongzhuozhuo/2021-git-demo.git |
添加远程地址
1
2xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git remote add origin https://github.com/xiongzhuozhuo/2021-git-demo.git添加远程仓库地址后,文件目录不会发生改变,但是.git/config文件发生了变化
1
2
3
4
5
6
7
8
9
10
11
12xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
cat .git/config
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[remote "origin"]
url = https://github.com/xiongzhuozhuo/2021-git-demo.git
fetch = +refs/heads/*:refs/remotes/origin/*将本地内容推送到远程master分支上
1
2
3
4
5
6
7
8
9
10
11
12
13xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git push -u origin master
Enumerating objects: 11, done.
Counting objects: 100% (11/11), done.
Delta compression using up to 8 threads
Compressing objects: 100% (6/6), done.
Writing objects: 100% (11/11), 760 bytes | 190.00 KiB/s, done.
Total 11 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/xiongzhuozhuo/2021-git-demo.git
* [new branch] master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
查看新增文件
①logs里有新增文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16xiong@SURFACE-PRO6 C:\Files\git-demo
tree .git/logs /f
卷 Local Disk 的文件夹 PATH 列表
卷序列号为 C0000100 F296:2801
C:\FILES\GIT-DEMO\.GIT\LOGS
│ HEAD
│
└─refs
├─heads
│ dev
│ master
│ tmp
│
└─remotes #新增
└─origin #新增
master #新增②refs里有新增文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15xiong@SURFACE-PRO6 C:\Files\git-demo
tree .git/refs /f
卷 Local Disk 的文件夹 PATH 列表
卷序列号为 C0000100 F296:2801
C:\FILES\GIT-DEMO\.GIT\REFS
├─heads
│ dev
│ master
│ tmp
│
├─remotes #新增
│ └─origin #新增
│ master #新增
│
└─tags因为此时是在master分支上将文件推送到远程服务器的,所以二者的指向应该相同,验证如下:
查看remotes里的master分支
1
2
3
4
5
6
7
8
xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
cat .git/refs/remotes/origin/master
a1431ae9fc3ef4f2ddd35c6a44349b69a5bd2f8b
xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git cat-file -t a1431a
commit指向的为一次提交
查看heads里的master分支
1
2
3xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
cat .git/refs/heads/master
a1431ae9fc3ef4f2ddd35c6a44349b69a5bd2f8b二者指向同一次提交
查看提交历史
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20xiong@Surface-pro6 MINGW64 /c/Files/git-demo (master)
git log
commit a1431ae9fc3ef4f2ddd35c6a44349b69a5bd2f8b (HEAD -> master, origin/master)
Author: xiongzhuo <xiongzhuo@outlook.com>
Date: Sat Aug 21 17:10:05 2021 +0800
3rd commit
commit 1928061d327bfa64a0a6ce3f4faa029b8c1ce776
Author: xiongzhuo <xiongzhuo@outlook.com>
Date: Sat Aug 21 16:14:06 2021 +0800
2nd commit
commit 8a44e8c0e81d4766b22777a61f3233d8b14497cc (tmp)
Author: xiongzhuo <xiongzhuo@outlook.com>
Date: Sat Aug 21 15:37:06 2021 +0800
1st commit
此时在本地做一次提交后,本地的master分支和远程仓库的master分支就不同步了
11. git 对象的压缩
12. SHA1插曲
13. git pack压缩
背景
在git里,文件会先压缩成blob对象进行存储,虽在在一定程度上减小了内存开销,但是由于每次对文件在工作区修改后,都需要将