Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion book/02-git-basics/sections/aliases.asc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ $ git config --global alias.unstage 'reset HEAD --'
[source,console]
----
$ git unstage fileA
$ git reset HEAD fileA
$ git reset HEAD -- fileA
----

这样看起来更清楚一些。
Expand Down
38 changes: 24 additions & 14 deletions book/02-git-basics/sections/recording-changes.asc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ Changes not staged for commit:
----

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

[source,console]
Expand Down Expand Up @@ -167,7 +169,9 @@ Changes to be committed:

==== 状态简览

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

[source,console]
----
Expand All @@ -179,7 +183,10 @@ M lib/simplegit.rb
?? LICENSE.txt
----

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

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

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

所谓的 glob 模式是指 shell 所使用的简化了的正则表达式。
Expand All @@ -222,7 +230,7 @@ $ cat .gitignore
# but do track lib.a, even though you're ignoring .a files above
!lib.a

# only ignore the root TODO file, not subdir/TODO
# only ignore the TODO file in the current directory, not subdir/TODO
/TODO

# ignore all files in the build/ directory
Expand All @@ -231,8 +239,8 @@ build/
# ignore doc/notes.txt, but not doc/server/arch.txt
doc/*.txt

# ignore all .txt files in the doc/ directory
doc/**/*.txt
# ignore all .pdf files in the doc/ directory
doc/**/*.pdf
----

[TIP]
Expand All @@ -258,7 +266,7 @@ On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

new file: README
modified: README

Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
Expand All @@ -281,7 +289,7 @@ index 8ebb991..643e24f 100644
if we have to read the whole diff to figure out why you're contributing
in the first place, you're less likely to get feedback and have your change
-merged in.
+merged in. Also, split your changes into comprehensive chunks if you patch is
+merged in. Also, split your changes into comprehensive chunks if your patch is
+longer than a dozen lines.

If you are starting to work on a particular area, feel free to submit a PR
Expand All @@ -308,12 +316,13 @@ index 0000000..03902a1
请注意,git diff 本身只显示尚未暂存的改动,而不是自上次提交以来所做的所有改动。
所以有时候你一下子暂存了所有更新过的文件后,运行 `git diff` 后却什么也没有,就是这个原因。

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

[source,console]
----
$ git add CONTRIBUTING.md
$ echo 'test line' >> CONTRIBUTING.md
$ echo '# test line' >> CONTRIBUTING.md
$ git status
On branch master
Changes to be committed:
Expand Down Expand Up @@ -358,18 +367,19 @@ index 8ebb991..643e24f 100644
if we have to read the whole diff to figure out why you're contributing
in the first place, you're less likely to get feedback and have your change
-merged in.
+merged in. Also, split your changes into comprehensive chunks if you patch is
+merged in. Also, split your changes into comprehensive chunks if your patch is
+longer than a dozen lines.

If you are starting to work on a particular area, feel free to submit a PR
that highlights your work in progress (and note in the PR title that it's
----

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

[[_committing_changes]]
Expand Down
3 changes: 2 additions & 1 deletion book/02-git-basics/sections/remotes.asc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ origin git@github.com:mojombo/grit.git (fetch)
origin git@github.com:mojombo/grit.git (push)
----

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

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

Expand Down
8 changes: 5 additions & 3 deletions book/02-git-basics/sections/undoing.asc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ $ git commit --amend

[source,console]
----
$ git add .
$ git add *
$ git status
On branch master
Changes to be committed:
Expand Down Expand Up @@ -79,7 +79,8 @@ Changes not staged for commit:

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

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

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

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

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

[source,console]
----
Expand Down