Skip to content

Commit 0f4af46

Browse files
committed
Merge pull request #249 from sanddudu/sync-02-git-basics
Sync 02-git-basics
2 parents 3cab1e9 + 43e366b commit 0f4af46

File tree

5 files changed

+35
-21
lines changed

5 files changed

+35
-21
lines changed

book/02-git-basics/sections/aliases.asc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ $ git config --global alias.unstage 'reset HEAD --'
3333
[source,console]
3434
----
3535
$ git unstage fileA
36-
$ git reset HEAD fileA
36+
$ git reset HEAD -- fileA
3737
----
3838

3939
这样看起来更清楚一些。

book/02-git-basics/sections/recording-changes.asc

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ Changes not staged for commit:
106106
----
107107

108108
文件 `CONTRIBUTING.md` 出现在 `Changes not staged for commit` 这行下面,说明已跟踪文件的内容发生了变化,但还没有放到暂存区。
109-
要暂存这次更新,需要运行 `git add` 命令。这是个多功能命令:可以用它开始跟踪新文件,或者把已跟踪的文件放到暂存区,还能用于合并时把有冲突的文件标记为已解决状态等。将这个命令理解为“添加内容到下一次提交中”而不是“将一个文件添加到项目中”要更加合适。(((git commands, add)))
109+
要暂存这次更新,需要运行 `git add` 命令。
110+
这是个多功能命令:可以用它开始跟踪新文件,或者把已跟踪的文件放到暂存区,还能用于合并时把有冲突的文件标记为已解决状态等。
111+
将这个命令理解为“添加内容到下一次提交中”而不是“将一个文件添加到项目中”要更加合适。(((git commands, add)))
110112
现在让我们运行 `git add` 将"CONTRIBUTING.md"放到暂存区,然后再看看 `git status` 的输出:
111113

112114
[source,console]
@@ -167,7 +169,9 @@ Changes to be committed:
167169

168170
==== 状态简览
169171

170-
`git status` 命令的输出十分详细,但其用语有些繁琐。如果你使用 `git status -s` 命令或 `git status --short` 命令,你将得到一种更为紧凑的格式输出。运行 `git status -s` ,状态报告输出如下:
172+
`git status` 命令的输出十分详细,但其用语有些繁琐。
173+
如果你使用 `git status -s` 命令或 `git status --short` 命令,你将得到一种更为紧凑的格式输出。
174+
运行 `git status -s` ,状态报告输出如下:
171175

172176
[source,console]
173177
----
@@ -179,7 +183,10 @@ M lib/simplegit.rb
179183
?? LICENSE.txt
180184
----
181185

182-
新添加的未跟踪文件前面有 `??` 标记,新添加到暂存区中的文件前面有 `A` 标记。修改过的文件前面有 `M` 标记,你可能注意到了 `M` 有两个可以出现的位置,出现在右边的 `M` 表示该文件被修改了但是还没放入暂存区,出现在靠左边的 `M` 表示该文件被修改了并放入了暂存区。例如,上面的状态报告显示: `README` 文件在工作区被修改了但是还没有将修改后的文件放入暂存区,`lib/simplegit.rb` 文件被修改了并将修改后的文件放入了暂存区,而 `Rakefile` 在工作区被修改并提交到暂存区后又在工作区中被修改了,所以在暂存区和工作区都有该文件被修改了的记录。
186+
新添加的未跟踪文件前面有 `??` 标记,新添加到暂存区中的文件前面有 `A` 标记,修改过的文件前面有 `M` 标记。
187+
你可能注意到了 `M` 有两个可以出现的位置,出现在右边的 `M` 表示该文件被修改了但是还没放入暂存区,出现在靠左边的 `M` 表示该文件被修改了并放入了暂存区。
188+
例如,上面的状态报告显示: `README` 文件在工作区被修改了但是还没有将修改后的文件放入暂存区,`lib/simplegit.rb` 文件被修改了并将修改后的文件放入了暂存区。
189+
而 `Rakefile` 在工作区被修改并提交到暂存区后又在工作区中被修改了,所以在暂存区和工作区都有该文件被修改了的记录。
183190

184191
[[_ignoring]]
185192
==== 忽略文件
@@ -205,7 +212,8 @@ $ cat .gitignore
205212

206213
* 所有空行或者以 `#` 开头的行都会被 Git 忽略。
207214
* 可以使用标准的 glob 模式匹配。
208-
* 匹配模式以(`/`)结尾说明要忽略的是目录。
215+
* 匹配模式可以以(`/`)开头防止递归。
216+
* 匹配模式可以以(`/`)结尾指定目录。
209217
* 要忽略指定模式以外的文件或目录,可以在模式前加上惊叹号(`!`)取反。
210218

211219
所谓的 glob 模式是指 shell 所使用的简化了的正则表达式。
@@ -222,7 +230,7 @@ $ cat .gitignore
222230
# but do track lib.a, even though you're ignoring .a files above
223231
!lib.a
224232
225-
# only ignore the root TODO file, not subdir/TODO
233+
# only ignore the TODO file in the current directory, not subdir/TODO
226234
/TODO
227235
228236
# ignore all files in the build/ directory
@@ -231,8 +239,8 @@ build/
231239
# ignore doc/notes.txt, but not doc/server/arch.txt
232240
doc/*.txt
233241
234-
# ignore all .txt files in the doc/ directory
235-
doc/**/*.txt
242+
# ignore all .pdf files in the doc/ directory
243+
doc/**/*.pdf
236244
----
237245

238246
[TIP]
@@ -258,7 +266,7 @@ On branch master
258266
Changes to be committed:
259267
(use "git reset HEAD <file>..." to unstage)
260268
261-
new file: README
269+
modified: README
262270
263271
Changes not staged for commit:
264272
(use "git add <file>..." to update what will be committed)
@@ -281,7 +289,7 @@ index 8ebb991..643e24f 100644
281289
if we have to read the whole diff to figure out why you're contributing
282290
in the first place, you're less likely to get feedback and have your change
283291
-merged in.
284-
+merged in. Also, split your changes into comprehensive chunks if you patch is
292+
+merged in. Also, split your changes into comprehensive chunks if your patch is
285293
+longer than a dozen lines.
286294
287295
If you are starting to work on a particular area, feel free to submit a PR
@@ -308,12 +316,13 @@ index 0000000..03902a1
308316
请注意,git diff 本身只显示尚未暂存的改动,而不是自上次提交以来所做的所有改动。
309317
所以有时候你一下子暂存了所有更新过的文件后,运行 `git diff` 后却什么也没有,就是这个原因。
310318

311-
像之前说的,暂存 `CONTRIBUTING.md` 后再编辑,运行 `git status` 会看到暂存前后的两个版本,如果我们的环境(终端输出)看起来如下:
319+
像之前说的,暂存 `CONTRIBUTING.md` 后再编辑,运行 `git status` 会看到暂存前后的两个版本。
320+
如果我们的环境(终端输出)看起来如下:
312321

313322
[source,console]
314323
----
315324
$ git add CONTRIBUTING.md
316-
$ echo 'test line' >> CONTRIBUTING.md
325+
$ echo '# test line' >> CONTRIBUTING.md
317326
$ git status
318327
On branch master
319328
Changes to be committed:
@@ -358,18 +367,19 @@ index 8ebb991..643e24f 100644
358367
if we have to read the whole diff to figure out why you're contributing
359368
in the first place, you're less likely to get feedback and have your change
360369
-merged in.
361-
+merged in. Also, split your changes into comprehensive chunks if you patch is
370+
+merged in. Also, split your changes into comprehensive chunks if your patch is
362371
+longer than a dozen lines.
363372
364373
If you are starting to work on a particular area, feel free to submit a PR
365374
that highlights your work in progress (and note in the PR title that it's
366375
----
367376

368-
[[_git_difftool]]
369377
[NOTE]
370378
.Git Diff 的插件版本
371379
====
372-
在本书中,我们使用 `git diff` 来分析文件差异。但是,如果你喜欢通过图形化的方式或其它格式输出方式的话,可以使用 `git difftool` 命令来用 Araxis ,emerge 或 vimdiff 等软件输出 diff 分析结果。使用 `git difftool --tool-help` 命令来看你的系统支持哪些 Git Diff 插件。
380+
在本书中,我们使用 `git diff` 来分析文件差异。
381+
但是,如果你喜欢通过图形化的方式或其它格式输出方式的话,可以使用 `git difftool` 命令来用 Araxis ,emerge 或 vimdiff 等软件输出 diff 分析结果。
382+
使用 `git difftool --tool-help` 命令来看你的系统支持哪些 Git Diff 插件。
373383
====
374384

375385
[[_committing_changes]]

book/02-git-basics/sections/remotes.asc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ origin [email protected]:mojombo/grit.git (fetch)
5656
origin [email protected]:mojombo/grit.git (push)
5757
----
5858

59-
这样我们可以轻松拉取其中任何一个用户的贡献。此外,我们大概还会有某些远程仓库的推送权限,虽然我们目前还不会在此介绍。
59+
这样我们可以轻松拉取其中任何一个用户的贡献。
60+
此外,我们大概还会有某些远程仓库的推送权限,虽然我们目前还不会在此介绍。
6061

6162
注意这些远程仓库使用了不同的协议;我们将会在 <<_git_on_the_server>> 中了解关于它们的更多信息。
6263

book/02-git-basics/sections/undoing.asc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ $ git commit --amend
4242

4343
[source,console]
4444
----
45-
$ git add .
45+
$ git add *
4646
$ git status
4747
On branch master
4848
Changes to be committed:
@@ -79,7 +79,8 @@ Changes not staged for commit:
7979

8080
[NOTE]
8181
=====
82-
虽然在调用时加上 `--hard` 选项**可以**令 `git reset` 成为一个危险的命令(译注:可能导致工作目录中所有当前进度丢失!),但本例中工作目录内的文件并不会被修改。不加选项地调用 `git reset` 并不危险——它只会修改暂存区域。
82+
虽然在调用时加上 `--hard` 选项**可以**令 `git reset` 成为一个危险的命令(译注:可能导致工作目录中所有当前进度丢失!),但本例中工作目录内的文件并不会被修改。
83+
不加选项地调用 `git reset` 并不危险 — 它只会修改暂存区域。
8384
=====
8485

8586
到目前为止这个神奇的调用就是你需要对 `git reset` 命令了解的全部。我们将会在 <<_git_reset>> 中了解 `reset` 的更多细节以及如何掌握它做一些真正有趣的事。
@@ -119,7 +120,8 @@ Changes to be committed:
119120

120121
[IMPORTANT]
121122
=====
122-
你需要知道 `git checkout -- [file]` 是一个危险的命令,这很重要。你对那个文件做的任何修改都会消失 - 你只是拷贝了另一个文件来覆盖它。
123+
你需要知道 `git checkout -- [file]` 是一个危险的命令,这很重要。
124+
你对那个文件做的任何修改都会消失 - 你只是拷贝了另一个文件来覆盖它。
123125
除非你确实清楚不想要那个文件了,否则不要使用这个命令。
124126
=====
125127

book/02-git-basics/sections/viewing-history.asc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ a11bef0 - Scott Chacon, 6 years ago : first commit
171171
| `%p` | 父对象的简短哈希字串
172172
| `%an` | 作者(author)的名字
173173
| `%ae` | 作者的电子邮件地址
174-
| `%ad` | 作者修订日期(可以用 -date= 选项定制格式)
174+
| `%ad` | 作者修订日期(可以用 --date= 选项定制格式)
175175
| `%ar` | 作者修订日期,按多久以前的方式显示
176176
| `%cn` | 提交者(committer)的名字
177177
| `%ce` | 提交者的电子邮件地址
@@ -245,7 +245,8 @@ $ git log --since=2.weeks
245245
用 `--author` 选项显示指定作者的提交,用 `--grep` 选项搜索提交说明中的关键字。
246246
(请注意,如果要得到同时满足这两个选项搜索条件的提交,就必须用 `--all-match` 选项。否则,满足任意一个条件的提交都会被匹配出来)
247247

248-
另一个非常有用的筛选选项是 `-S`,可以列出那些添加或移除了某些字符串的提交。比如说,你想找出添加或移除了某一个特定函数的引用的提交,你可以这样使用:
248+
另一个非常有用的筛选选项是 `-S`,可以列出那些添加或移除了某些字符串的提交。
249+
比如说,你想找出添加或移除了某一个特定函数的引用的提交,你可以这样使用:
249250

250251
[source,console]
251252
----

0 commit comments

Comments
 (0)