Skip to content

Commit dfe80e4

Browse files
committed
Merge pull request #164 from networm/07-git-tools_interactive-staging
Translate 07-git-tools interactive-staging
2 parents a583de8 + f1754d9 commit dfe80e4

File tree

1 file changed

+37
-37
lines changed

1 file changed

+37
-37
lines changed

book/07-git-tools/sections/interactive-staging.asc

+37-37
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[[_interactive_staging]]
2-
=== Interactive Staging
2+
=== 交互式暂存
33

4-
Git comes with a couple of scripts that make some command-line tasks easier.
5-
Here, you’ll look at a few interactive commands that can help you easily craft your commits to include only certain combinations and parts of files.
6-
These tools are very helpful if you modify a bunch of files and then decide that you want those changes to be in several focused commits rather than one big messy commit.
7-
This way, you can make sure your commits are logically separate changesets and can be easily reviewed by the developers working with you.
8-
If you run `git add` with the `-i` or `--interactive` option, Git goes into an interactive shell mode, displaying something like this:
4+
Git 自带的一些脚本可以使在命令行下工作更容易。
5+
本节的几个互交命令可以帮助你将文件的特定部分组合成提交。
6+
当你修改一组文件后,希望这些改动能放到若干提交而不是混杂在一起成为一个提交时,这几个工具会非常有用。
7+
通过这种方式,可以确保提交是逻辑上独立的变更集,同时也会使其他开发者在与你工作时很容易地审核。
8+
如果运行 `git adds` 时使用 `-i` 或者 `--interactive` 选项,Git 将会进入一个交互式终端模式,显示类似下面的东西:
99

1010
[source,console]
1111
----
@@ -21,15 +21,15 @@ $ git add -i
2121
What now>
2222
----
2323

24-
You can see that this command shows you a much different view of your staging area – basically the same information you get with `git status` but a bit more succinct and informative.
25-
It lists the changes you’ve staged on the left and unstaged changes on the right.
24+
可以看到这个命令以非常不同的视图显示了暂存区 - 基本上与 `git status` 是相同的信息,但是更简明扼要一些。
25+
它将暂存的修改列在左侧,未暂存的修改列在右侧。
2626

27-
After this comes a Commands section.
28-
Here you can do a number of things, including staging files, unstaging files, staging parts of files, adding untracked files, and seeing diffs of what has been staged.
27+
在这块区域后是命令区域。
28+
在这里你可以做一些工作,包括暂存文件、取消暂存文件、暂存文件的一部分、添加未被追踪的文件、查看暂存内容的区别。
2929

30-
==== Staging and Unstaging Files
30+
==== 暂存与取消暂存文件
3131

32-
If you type `2` or `u` at the `What now>` prompt, the script prompts you for which files you want to stage:
32+
如果在 `What now>` 提示符后键入 `2` 或 `u`,脚本将会提示想要暂存哪个文件:
3333

3434
[source,console]
3535
----
@@ -41,7 +41,7 @@ What now> 2
4141
Update>>
4242
----
4343

44-
To stage the TODO and index.html files, you can type the numbers:
44+
要暂存 TODO index.html 文件,可以输入数字:
4545

4646
[source,console]
4747
----
@@ -53,8 +53,8 @@ Update>> 1,2
5353
Update>>
5454
----
5555

56-
The `*` next to each file means the file is selected to be staged.
57-
If you press Enter after typing nothing at the `Update>>` prompt, Git takes anything selected and stages it for you:
56+
每个文件前面的 `*` 意味着选中的文件将会被暂存。
57+
如果在 `Update>>` 提示符后不输入任何东西并直接按回车,Git 将会暂存之前选择的文件:
5858

5959
[source,console]
6060
----
@@ -71,8 +71,8 @@ What now> 1
7171
3: unchanged +5/-1 lib/simplegit.rb
7272
----
7373

74-
Now you can see that the TODO and index.html files are staged and the simplegit.rb file is still unstaged.
75-
If you want to unstage the TODO file at this point, you use the `3` or `r` (for revert) option:
74+
现在可以看到 TODO index.html 文件已经被暂存而 simplegit.rb 文件还未被暂存。
75+
如果这时想要取消暂存 TODO 文件,使用 `3` `r`(撤消)选项:
7676

7777
[source,console]
7878
----
@@ -93,7 +93,7 @@ Revert>> [enter]
9393
reverted one path
9494
----
9595

96-
Looking at your Git status again, you can see that you’ve unstaged the TODO file:
96+
再次查看 Git 状态,可以看到已经取消暂存 TODO 文件:
9797

9898
[source,console]
9999
----
@@ -107,9 +107,9 @@ What now> 1
107107
3: unchanged +5/-1 lib/simplegit.rb
108108
----
109109

110-
To see the diff of what you’ve staged, you can use the `6` or `d` (for diff) command.
111-
It shows you a list of your staged files, and you can select the ones for which you would like to see the staged diff.
112-
This is much like specifying `git diff --cached` on the command line:
110+
如果想要查看已暂存内容的区别,可以使用 `6` `d`(区别)命令。
111+
它会显示暂存文件的一个列表,可以从中选择想要查看的暂存区别。
112+
这跟你在命令行指定 `git diff --cached` 非常相似:
113113

114114
[source,console]
115115
----
@@ -134,14 +134,14 @@ index 4d07108..4335f49 100644
134134
<script type="text/javascript">
135135
----
136136

137-
With these basic commands, you can use the interactive add mode to deal with your staging area a little more easily.
137+
通过这些基本命令,可以使用交互式添加模式来轻松地处理暂存区。
138138

139-
==== Staging Patches
139+
==== 暂存补丁
140140

141-
It’s also possible for Git to stage certain parts of files and not the rest.
142-
For example, if you make two changes to your simplegit.rb file and want to stage one of them and not the other, doing so is very easy in Git.
143-
From the interactive prompt, type `5` or `p` (for patch).
144-
Git will ask you which files you would like to partially stage; then, for each section of the selected files, it will display hunks of the file diff and ask if you would like to stage them, one by one:
141+
Git 也可以暂存文件的特定部分。
142+
例如,如果在 simplegit.rb 文件中做了两处修改,但只想要暂存其中的一个而不是另一个,Git 会帮你轻松地完成。
143+
从交互式提示符中,输入 `5` `p`(补丁)。
144+
Git 会询问你想要部分暂存哪些文件;然后,对已选择文件的每一个部分,它都会一个个地显示文件区别并询问你是否想要暂存它们:
145145

146146
[source,console]
147147
----
@@ -161,8 +161,8 @@ index dd5ecc4..57399e0 100644
161161
Stage this hunk [y,n,a,d,/,j,J,g,e,?]?
162162
----
163163

164-
You have a lot of options at this point.
165-
Typing `?` shows a list of what you can do:
164+
这时有很多选项。
165+
输入 `?` 显示所有可以使用的命令列表:
166166

167167
[source,console]
168168
----
@@ -182,8 +182,8 @@ e - manually edit the current hunk
182182
? - print help
183183
----
184184

185-
Generally, you’ll type `y` or `n` if you want to stage each hunk, but staging all of them in certain files or skipping a hunk decision until later can be helpful too.
186-
If you stage one part of the file and leave another part unstaged, your status output will look like this:
185+
通常情况下可以输入 y 或 n 来选择是否要暂存每一个区块,当然,暂存特定文件中的所有部分或为之后的选择跳过一个区块也是非常有用的。
186+
如果你只暂存文件的一部分,状态输出可能会像下面这样:
187187

188188
[source,console]
189189
----
@@ -194,11 +194,11 @@ What now> 1
194194
3: +1/-1 +4/-0 lib/simplegit.rb
195195
----
196196

197-
The status of the simplegit.rb file is interesting.
198-
It shows you that a couple of lines are staged and a couple are unstaged.
199-
You’ve partially staged this file.
200-
At this point, you can exit the interactive adding script and run `git commit` to commit the partially staged files.
197+
simplegit.rb 文件的状态很有趣。
198+
它显示出若干行被暂存与若干行未被暂存。
199+
已经部分地暂存了这个文件。
200+
在这时,可以退出交互式添加脚本并且运行 `git commit` 来提交部分暂存的文件。
201201

202-
You also don’t need to be in interactive add mode to do the partial-file staging – you can start the same script by using `git add -p` or `git add --patch` on the command line.
202+
也可以不必在交互式添加模式中做部分文件暂存 - 可以在命令行中使用 `git add -p` `git add --patch` 来启动同样的脚本。
203203

204-
Furthermore, you can use patch mode for partially resetting files with the `reset --patch` command, for checking out parts of files with the `checkout --patch` command and for stashing parts of files with the `stash save --patch` command. We'll go into more details on each of these as we get to more advanced usages of these commands.
204+
更进一步地,可以使用 `reset --patch` 命令的补丁模式来部分重置文件。通过 `checkout --patch` 命令来部分检出文件与 `stash save --patch` 命令来部分暂存文件。我们将会在接触这些命令的高级使用方法时了解更多详细信息。

0 commit comments

Comments
 (0)