1- [ 🎉 面试进阶指南已上线] ( https://xiaozhuanlan.com/CyC2018 )
2- <!-- GFM-TOC -->
3- * [ 集中式与分布式] ( #集中式与分布式 )
4- * [ 中心服务器] ( #中心服务器 )
5- * [ 工作流] ( #工作流 )
6- * [ 分支实现] ( #分支实现 )
7- * [ 冲突] ( #冲突 )
8- * [ Fast forward] ( #fast-forward )
9- * [ 分支管理策略] ( #分支管理策略 )
10- * [ 储藏(Stashing)] ( #储藏stashing )
11- * [ SSH 传输设置] ( #ssh-传输设置 )
12- * [ .gitignore 文件] ( #gitignore-文件 )
13- * [ Git 命令一览] ( #git-命令一览 )
14- * [ 参考资料] ( #参考资料 )
15- <!-- GFM-TOC -->
16-
17-
18- # 集中式与分布式
19-
20- Git 属于分布式版本控制系统,而 SVN 属于集中式。
1+ # 集中式与分布式
2+
3+ Git 属于分布式版本控制系统,而 SVN 属于集中式。
214
225集中式版本控制只有中心服务器拥有一份代码,而分布式版本控制每个人的电脑上就有一份完整的代码。
236
@@ -27,133 +10,133 @@ Git 属于分布式版本控制系统,而 SVN 属于集中式。
2710
2811分布式版本控制新建分支、合并分支操作速度非常快,而集中式版本控制新建一个分支相当于复制一份完整代码。
2912
30- # 中心服务器
13+ # 中心服务器
3114
32- 中心服务器用来交换每个用户的修改,没有中心服务器也能工作,但是中心服务器能够 24 小时保持开机状态,这样就能更方便的交换修改。
15+ 中心服务器用来交换每个用户的修改,没有中心服务器也能工作,但是中心服务器能够 24 小时保持开机状态,这样就能更方便的交换修改。
3316
34- Github 就是一个中心服务器。
17+ Github 就是一个中心服务器。
3518
36- # 工作流
19+ # 工作流
3720
38- < div align = " center " > < img src = " pics /a1198642-9159-4d88-8aec-c3b04e7a2563.jpg" /> </ div >< br >
21+ ![ ] ( index_files /a1198642-9159-4d88-8aec-c3b04e7a2563.jpg)
3922
40- 新建一个仓库之后,当前目录就成为了工作区,工作区下有一个隐藏目录 .git,它属于 Git 的版本库。
23+ 新建一个仓库之后,当前目录就成为了工作区,工作区下有一个隐藏目录 .git,它属于 Git 的版本库。
4124
42- Git 版本库有一个称为 stage 的暂存区,还有自动创建的 master 分支以及指向分支的 HEAD 指针。
25+ Git 版本库有一个称为 stage 的暂存区,还有自动创建的 master 分支以及指向分支的 HEAD 指针。
4326
44- < div align = " center " > < img src = " pics /46f66e88-e65a-4ad0-a060-3c63fe22947c.png" /> </ div >< br >
27+ ![ ] ( index_files /46f66e88-e65a-4ad0-a060-3c63fe22947c.png)
4528
46- - git add files 把文件的修改添加到暂存区
47- - git commit 把暂存区的修改提交到当前分支,提交之后暂存区就被清空了
48- - git reset -- files 使用当前分支上的修改覆盖暂存区,用来撤销最后一次 git add files
49- - git checkout -- files 使用暂存区的修改覆盖工作目录,用来撤销本地修改
29+ - git add files 把文件的修改添加到暂存区
30+ - git commit 把暂存区的修改提交到当前分支,提交之后暂存区就被清空了
31+ - git reset -- files 使用当前分支上的修改覆盖暂存区,用来撤销最后一次 git add files
32+ - git checkout -- files 使用暂存区的修改覆盖工作目录,用来撤销本地修改
5033
51- < div align = " center " > < img src = " pics /17976404-95f5-480e-9cb4-250e6aa1d55f.png" /> </ div >< br >
34+ ![ ] ( index_files /17976404-95f5-480e-9cb4-250e6aa1d55f.png)
5235
5336可以跳过暂存区域直接从分支中取出修改,或者直接提交修改到分支中。
5437
55- - git commit -a 直接把所有文件的修改添加到暂存区然后执行提交
56- - git checkout HEAD -- files 取出最后一次修改,可以用来进行回滚操作
38+ - git commit -a 直接把所有文件的修改添加到暂存区然后执行提交
39+ - git checkout HEAD -- files 取出最后一次修改,可以用来进行回滚操作
5740
58- # 分支实现
41+ # 分支实现
5942
60- 使用指针将每个提交连接成一条时间线,HEAD 指针指向当前分支指针。
43+ 使用指针将每个提交连接成一条时间线,HEAD 指针指向当前分支指针。
6144
62- < div align = " center " > < img src = " pics /fb546e12-e1fb-4b72-a1fb-8a7f5000dce6.jpg" /> </ div >< br >
45+ ![ ] ( index_files /fb546e12-e1fb-4b72-a1fb-8a7f5000dce6.jpg)
6346
64- 新建分支是新建一个指针指向时间线的最后一个节点,并让 HEAD 指针指向新分支表示新分支成为当前分支。
47+ 新建分支是新建一个指针指向时间线的最后一个节点,并让 HEAD 指针指向新分支表示新分支成为当前分支。
6548
66- < div align = " center " > < img src = " pics /bc775758-89ab-4805-9f9c-78b8739cf780.jpg" /> </ div >< br >
49+ ![ ] ( index_files /bc775758-89ab-4805-9f9c-78b8739cf780.jpg)
6750
6851每次提交只会让当前分支指针向前移动,而其它分支指针不会移动。
6952
70- < div align = " center " > < img src = " pics /5292faa6-0141-4638-bf0f-bb95b081dcba.jpg" /> </ div >< br >
53+ ![ ] ( index_files /5292faa6-0141-4638-bf0f-bb95b081dcba.jpg)
7154
7255合并分支也只需要改变指针即可。
7356
74- < div align = " center " > < img src = " pics /1164a71f-413d-494a-9cc8-679fb6a2613d.jpg" /> </ div >< br >
57+ ![ ] ( index_files /1164a71f-413d-494a-9cc8-679fb6a2613d.jpg)
7558
76- # 冲突
59+ # 冲突
7760
7861当两个分支都对同一个文件的同一行进行了修改,在分支合并时就会产生冲突。
7962
80- < div align = " center " > < img src = " pics /58e57a21-6b6b-40b6-af85-956dd4e0f55a.jpg" /> </ div >< br >
63+ ![ ] ( index_files /58e57a21-6b6b-40b6-af85-956dd4e0f55a.jpg)
8164
82- Git 会使用 <<<<<<< ,======= ,>>>>>>> 标记出不同分支的内容,只需要把不同分支中冲突部分修改成一样就能解决冲突。
65+ Git 会使用 <<<<<<< ,======= ,>>>>>>> 标记出不同分支的内容,只需要把不同分支中冲突部分修改成一样就能解决冲突。
8366
8467```
85- <<<<<<< HEAD
86- Creating a new branch is quick & simple.
68+ <<<<<<< HEAD
69+ Creating a new branch is quick & simple.
8770=======
88- Creating a new branch is quick AND simple.
89- >>>>>>> feature1
71+ Creating a new branch is quick AND simple.
72+ >>>>>>> feature1
9073```
9174
92- # Fast forward
75+ # Fast forward
9376
94- "快进式合并"(fast-farward merge),会直接将 master 分支指向合并的分支,这种模式下进行分支合并会丢失分支信息,也就不能在分支历史上看出分支信息。
77+ "快进式合并"(fast-farward merge),会直接将 master 分支指向合并的分支,这种模式下进行分支合并会丢失分支信息,也就不能在分支历史上看出分支信息。
9578
96- 可以在合并时加上 --no-ff 参数来禁用 Fast forward 模式,并且加上 -m 参数让合并时产生一个新的 commit。
79+ 可以在合并时加上 --no-ff 参数来禁用 Fast forward 模式,并且加上 -m 参数让合并时产生一个新的 commit。
9780
9881```
99- $ git merge --no-ff -m "merge with no-ff" dev
82+ $ git merge --no-ff -m "merge with no-ff" dev
10083```
10184
102- < div align = " center " > < img src = " pics /dd78a1fe-1ff3-4bcf-a56f-8c003995beb6.jpg" /> </ div >< br >
85+ ![ ] ( index_files /dd78a1fe-1ff3-4bcf-a56f-8c003995beb6.jpg)
10386
104- # 分支管理策略
87+ # 分支管理策略
10588
106- master 分支应该是非常稳定的,只用来发布新版本;
89+ master 分支应该是非常稳定的,只用来发布新版本;
10790
108- 日常开发在开发分支 dev 上进行。
91+ 日常开发在开发分支 dev 上进行。
10992
110- < div align = " center " > < img src = " pics /245fd2fb-209c-4ad5-bc5e-eb5664966a0e.jpg" /> </ div >< br >
93+ ![ ] ( index_files /245fd2fb-209c-4ad5-bc5e-eb5664966a0e.jpg)
11194
112- # 储藏(Stashing)
95+ # 储藏(Stashing)
11396
11497在一个分支上操作之后,如果还没有将修改提交到分支上,此时进行切换分支,那么另一个分支上也能看到新的修改。这是因为所有分支都共用一个工作区的缘故。
11598
116- 可以使用 git stash 将当前分支的修改储藏起来,此时当前工作区的所有修改都会被存到栈上,也就是说当前工作区是干净的,没有任何未提交的修改。此时就可以安全的切换到其它分支上了。
99+ 可以使用 git stash 将当前分支的修改储藏起来,此时当前工作区的所有修改都会被存到栈上,也就是说当前工作区是干净的,没有任何未提交的修改。此时就可以安全的切换到其它分支上了。
117100
118101```
119- $ git stash
120- Saved working directory and index state \ "WIP on master: 049d078 added the index file"
121- HEAD is now at 049d078 added the index file (To restore them type "git stash apply")
102+ $ git stash
103+ Saved working directory and index state \ "WIP on master: 049d078 added the index file"
104+ HEAD is now at 049d078 added the index file (To restore them type "git stash apply")
122105```
123106
124- 该功能可以用于 bug 分支的实现。如果当前正在 dev 分支上进行开发,但是此时 master 上有个 bug 需要修复,但是 dev 分支上的开发还未完成,不想立即提交。在新建 bug 分支并切换到 bug 分支之前就需要使用 git stash 将 dev 分支的未提交修改储藏起来。
107+ 该功能可以用于 bug 分支的实现。如果当前正在 dev 分支上进行开发,但是此时 master 上有个 bug 需要修复,但是 dev 分支上的开发还未完成,不想立即提交。在新建 bug 分支并切换到 bug 分支之前就需要使用 git stash 将 dev 分支的未提交修改储藏起来。
125108
126- # SSH 传输设置
109+ # SSH 传输设置
127110
128- Git 仓库和 Github 中心仓库之间的传输是通过 SSH 加密。
111+ Git 仓库和 Github 中心仓库之间的传输是通过 SSH 加密。
129112
130- 如果工作区下没有 .ssh 目录,或者该目录下没有 id_rsa 和 id_rsa.pub 这两个文件,可以通过以下命令来创建 SSH Key:
113+ 如果工作区下没有 .ssh 目录,或者该目录下没有 id_rsa 和 id_rsa.pub 这两个文件,可以通过以下命令来创建 SSH Key:
131114
132115```
133- $ ssh-keygen -t rsa -C "youremail@example.com"
116+ $ ssh-keygen -t rsa -C "youremail@example.com"
134117```
135118
136- 然后把公钥 id_rsa.pub 的内容复制到 Github "Account settings" 的 SSH Keys 中。
119+ 然后把公钥 id_rsa.pub 的内容复制到 Github "Account settings" 的 SSH Keys 中。
137120
138- # .gitignore 文件
121+ # .gitignore 文件
139122
140123忽略以下文件:
141124
142- - 操作系统自动生成的文件,比如缩略图;
143- - 编译生成的中间文件,比如 Java 编译产生的 .class 文件;
144- - 自己的敏感信息,比如存放口令的配置文件。
125+ - 操作系统自动生成的文件,比如缩略图;
126+ - 编译生成的中间文件,比如 Java 编译产生的 .class 文件;
127+ - 自己的敏感信息,比如存放口令的配置文件。
145128
146- 不需要全部自己编写,可以到 [ https://github.com/github/gitignore ] ( https://github.com/github/gitignore ) 中进行查询。
129+ 不需要全部自己编写,可以到 [ https://github.com/github/gitignore ] ( https://github.com/github/gitignore ) 中进行查询。
147130
148- # Git 命令一览
131+ # Git 命令一览
149132
150- < div align = " center " > < img src = " pics /7a29acce-f243-4914-9f00-f2988c528412.jpg" /> </ div >< br >
133+ ![ ] ( index_files /7a29acce-f243-4914-9f00-f2988c528412.jpg)
151134
152135比较详细的地址:http://www.cheat-sheets.org/saved-copy/git-cheat-sheet.pdf
153136
154- # 参考资料
137+ # 参考资料
155138
156- - [ Git - 简明指南] ( http://rogerdudler.github.io/git-guide/index.zh.html )
157- - [ 图解 Git] ( http://marklodato.github.io/visual-git-guide/index-zh-cn.html )
158- - [ 廖雪峰 : Git 教程] ( https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000 )
159- - [ Learn Git Branching] ( https://learngitbranching.js.org/ )
139+ - [ Git - 简明指南] ( http://rogerdudler.github.io/git-guide/index.zh.html )
140+ - [ 图解 Git] ( http://marklodato.github.io/visual-git-guide/index-zh-cn.html )
141+ - [ 廖雪峰 : Git 教程] ( https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000 )
142+ - [ Learn Git Branching] ( https://learngitbranching.js.org/ )
0 commit comments