1- # 集中式与分布式
2-
3- Git 属于分布式版本控制系统,而 SVN 属于集中式。
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 属于集中式。
421
522集中式版本控制只有中心服务器拥有一份代码,而分布式版本控制每个人的电脑上就有一份完整的代码。
623
@@ -10,133 +27,133 @@ Git 属于分布式版本控制系统,而 SVN 属于集中式。
1027
1128分布式版本控制新建分支、合并分支操作速度非常快,而集中式版本控制新建一个分支相当于复制一份完整代码。
1229
13- # 中心服务器
30+ # 中心服务器
1431
15- 中心服务器用来交换每个用户的修改,没有中心服务器也能工作,但是中心服务器能够 24 小时保持开机状态,这样就能更方便的交换修改。
32+ 中心服务器用来交换每个用户的修改,没有中心服务器也能工作,但是中心服务器能够 24 小时保持开机状态,这样就能更方便的交换修改。
1633
17- Github 就是一个中心服务器。
34+ Github 就是一个中心服务器。
1835
19- # 工作流
36+ # 工作流
2037
21- ![ ] ( index_files /a1198642-9159-4d88-8aec-c3b04e7a2563.jpg)
38+ < div align = " center " > < img src = " pics /a1198642-9159-4d88-8aec-c3b04e7a2563.jpg" /> </ div >< br >
2239
23- 新建一个仓库之后,当前目录就成为了工作区,工作区下有一个隐藏目录 .git,它属于 Git 的版本库。
40+ 新建一个仓库之后,当前目录就成为了工作区,工作区下有一个隐藏目录 .git,它属于 Git 的版本库。
2441
25- Git 版本库有一个称为 stage 的暂存区,还有自动创建的 master 分支以及指向分支的 HEAD 指针。
42+ Git 版本库有一个称为 stage 的暂存区,还有自动创建的 master 分支以及指向分支的 HEAD 指针。
2643
27- ![ ] ( index_files /46f66e88-e65a-4ad0-a060-3c63fe22947c.png)
44+ < div align = " center " > < img src = " pics /46f66e88-e65a-4ad0-a060-3c63fe22947c.png" /> </ div >< br >
2845
29- - git add files 把文件的修改添加到暂存区
30- - git commit 把暂存区的修改提交到当前分支,提交之后暂存区就被清空了
31- - git reset -- files 使用当前分支上的修改覆盖暂存区,用来撤销最后一次 git add files
32- - git checkout -- files 使用暂存区的修改覆盖工作目录,用来撤销本地修改
46+ - git add files 把文件的修改添加到暂存区
47+ - git commit 把暂存区的修改提交到当前分支,提交之后暂存区就被清空了
48+ - git reset -- files 使用当前分支上的修改覆盖暂存区,用来撤销最后一次 git add files
49+ - git checkout -- files 使用暂存区的修改覆盖工作目录,用来撤销本地修改
3350
34- ![ ] ( index_files /17976404-95f5-480e-9cb4-250e6aa1d55f.png)
51+ < div align = " center " > < img src = " pics /17976404-95f5-480e-9cb4-250e6aa1d55f.png" /> </ div >< br >
3552
3653可以跳过暂存区域直接从分支中取出修改,或者直接提交修改到分支中。
3754
38- - git commit -a 直接把所有文件的修改添加到暂存区然后执行提交
39- - git checkout HEAD -- files 取出最后一次修改,可以用来进行回滚操作
55+ - git commit -a 直接把所有文件的修改添加到暂存区然后执行提交
56+ - git checkout HEAD -- files 取出最后一次修改,可以用来进行回滚操作
4057
41- # 分支实现
58+ # 分支实现
4259
43- 使用指针将每个提交连接成一条时间线,HEAD 指针指向当前分支指针。
60+ 使用指针将每个提交连接成一条时间线,HEAD 指针指向当前分支指针。
4461
45- ![ ] ( index_files /fb546e12-e1fb-4b72-a1fb-8a7f5000dce6.jpg)
62+ < div align = " center " > < img src = " pics /fb546e12-e1fb-4b72-a1fb-8a7f5000dce6.jpg" /> </ div >< br >
4663
47- 新建分支是新建一个指针指向时间线的最后一个节点,并让 HEAD 指针指向新分支表示新分支成为当前分支。
64+ 新建分支是新建一个指针指向时间线的最后一个节点,并让 HEAD 指针指向新分支表示新分支成为当前分支。
4865
49- ![ ] ( index_files /bc775758-89ab-4805-9f9c-78b8739cf780.jpg)
66+ < div align = " center " > < img src = " pics /bc775758-89ab-4805-9f9c-78b8739cf780.jpg" /> </ div >< br >
5067
5168每次提交只会让当前分支指针向前移动,而其它分支指针不会移动。
5269
53- ![ ] ( index_files /5292faa6-0141-4638-bf0f-bb95b081dcba.jpg)
70+ < div align = " center " > < img src = " pics /5292faa6-0141-4638-bf0f-bb95b081dcba.jpg" /> </ div >< br >
5471
5572合并分支也只需要改变指针即可。
5673
57- ![ ] ( index_files /1164a71f-413d-494a-9cc8-679fb6a2613d.jpg)
74+ < div align = " center " > < img src = " pics /1164a71f-413d-494a-9cc8-679fb6a2613d.jpg" /> </ div >< br >
5875
59- # 冲突
76+ # 冲突
6077
6178当两个分支都对同一个文件的同一行进行了修改,在分支合并时就会产生冲突。
6279
63- ![ ] ( index_files /58e57a21-6b6b-40b6-af85-956dd4e0f55a.jpg)
80+ < div align = " center " > < img src = " pics /58e57a21-6b6b-40b6-af85-956dd4e0f55a.jpg" /> </ div >< br >
6481
65- Git 会使用 <<<<<<< ,======= ,>>>>>>> 标记出不同分支的内容,只需要把不同分支中冲突部分修改成一样就能解决冲突。
82+ Git 会使用 <<<<<<< ,======= ,>>>>>>> 标记出不同分支的内容,只需要把不同分支中冲突部分修改成一样就能解决冲突。
6683
6784```
68- <<<<<<< HEAD
69- Creating a new branch is quick & simple.
85+ <<<<<<< HEAD
86+ Creating a new branch is quick & simple.
7087=======
71- Creating a new branch is quick AND simple.
72- >>>>>>> feature1
88+ Creating a new branch is quick AND simple.
89+ >>>>>>> feature1
7390```
7491
75- # Fast forward
92+ # Fast forward
7693
77- "快进式合并"(fast-farward merge),会直接将 master 分支指向合并的分支,这种模式下进行分支合并会丢失分支信息,也就不能在分支历史上看出分支信息。
94+ "快进式合并"(fast-farward merge),会直接将 master 分支指向合并的分支,这种模式下进行分支合并会丢失分支信息,也就不能在分支历史上看出分支信息。
7895
79- 可以在合并时加上 --no-ff 参数来禁用 Fast forward 模式,并且加上 -m 参数让合并时产生一个新的 commit。
96+ 可以在合并时加上 --no-ff 参数来禁用 Fast forward 模式,并且加上 -m 参数让合并时产生一个新的 commit。
8097
8198```
82- $ git merge --no-ff -m "merge with no-ff" dev
99+ $ git merge --no-ff -m "merge with no-ff" dev
83100```
84101
85- ![ ] ( index_files /dd78a1fe-1ff3-4bcf-a56f-8c003995beb6.jpg)
102+ < div align = " center " > < img src = " pics /dd78a1fe-1ff3-4bcf-a56f-8c003995beb6.jpg" /> </ div >< br >
86103
87- # 分支管理策略
104+ # 分支管理策略
88105
89- master 分支应该是非常稳定的,只用来发布新版本;
106+ master 分支应该是非常稳定的,只用来发布新版本;
90107
91- 日常开发在开发分支 dev 上进行。
108+ 日常开发在开发分支 dev 上进行。
92109
93- ![ ] ( index_files /245fd2fb-209c-4ad5-bc5e-eb5664966a0e.jpg)
110+ < div align = " center " > < img src = " pics /245fd2fb-209c-4ad5-bc5e-eb5664966a0e.jpg" /> </ div >< br >
94111
95- # 储藏(Stashing)
112+ # 储藏(Stashing)
96113
97114在一个分支上操作之后,如果还没有将修改提交到分支上,此时进行切换分支,那么另一个分支上也能看到新的修改。这是因为所有分支都共用一个工作区的缘故。
98115
99- 可以使用 git stash 将当前分支的修改储藏起来,此时当前工作区的所有修改都会被存到栈上,也就是说当前工作区是干净的,没有任何未提交的修改。此时就可以安全的切换到其它分支上了。
116+ 可以使用 git stash 将当前分支的修改储藏起来,此时当前工作区的所有修改都会被存到栈上,也就是说当前工作区是干净的,没有任何未提交的修改。此时就可以安全的切换到其它分支上了。
100117
101118```
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")
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")
105122```
106123
107- 该功能可以用于 bug 分支的实现。如果当前正在 dev 分支上进行开发,但是此时 master 上有个 bug 需要修复,但是 dev 分支上的开发还未完成,不想立即提交。在新建 bug 分支并切换到 bug 分支之前就需要使用 git stash 将 dev 分支的未提交修改储藏起来。
124+ 该功能可以用于 bug 分支的实现。如果当前正在 dev 分支上进行开发,但是此时 master 上有个 bug 需要修复,但是 dev 分支上的开发还未完成,不想立即提交。在新建 bug 分支并切换到 bug 分支之前就需要使用 git stash 将 dev 分支的未提交修改储藏起来。
108125
109- # SSH 传输设置
126+ # SSH 传输设置
110127
111- Git 仓库和 Github 中心仓库之间的传输是通过 SSH 加密。
128+ Git 仓库和 Github 中心仓库之间的传输是通过 SSH 加密。
112129
113- 如果工作区下没有 .ssh 目录,或者该目录下没有 id_rsa 和 id_rsa.pub 这两个文件,可以通过以下命令来创建 SSH Key:
130+ 如果工作区下没有 .ssh 目录,或者该目录下没有 id_rsa 和 id_rsa.pub 这两个文件,可以通过以下命令来创建 SSH Key:
114131
115132```
116- $ ssh-keygen -t rsa -C "youremail@example.com"
133+ $ ssh-keygen -t rsa -C "youremail@example.com"
117134```
118135
119- 然后把公钥 id_rsa.pub 的内容复制到 Github "Account settings" 的 SSH Keys 中。
136+ 然后把公钥 id_rsa.pub 的内容复制到 Github "Account settings" 的 SSH Keys 中。
120137
121- # .gitignore 文件
138+ # .gitignore 文件
122139
123140忽略以下文件:
124141
125- - 操作系统自动生成的文件,比如缩略图;
126- - 编译生成的中间文件,比如 Java 编译产生的 .class 文件;
127- - 自己的敏感信息,比如存放口令的配置文件。
142+ - 操作系统自动生成的文件,比如缩略图;
143+ - 编译生成的中间文件,比如 Java 编译产生的 .class 文件;
144+ - 自己的敏感信息,比如存放口令的配置文件。
128145
129- 不需要全部自己编写,可以到 [ https://github.com/github/gitignore ] ( https://github.com/github/gitignore ) 中进行查询。
146+ 不需要全部自己编写,可以到 [ https://github.com/github/gitignore ] ( https://github.com/github/gitignore ) 中进行查询。
130147
131- # Git 命令一览
148+ # Git 命令一览
132149
133- ![ ] ( index_files /7a29acce-f243-4914-9f00-f2988c528412.jpg)
150+ < div align = " center " > < img src = " pics /7a29acce-f243-4914-9f00-f2988c528412.jpg" /> </ div >< br >
134151
135152比较详细的地址:http://www.cheat-sheets.org/saved-copy/git-cheat-sheet.pdf
136153
137- # 参考资料
154+ # 参考资料
138155
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/ )
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/ )
0 commit comments