Skip to content

Commit d53932d

Browse files
committed
Sync 02-git-basics recording-changes.
1 parent b868dee commit d53932d

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

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]]

0 commit comments

Comments
 (0)