Skip to content

Commit a583de8

Browse files
committed
Merge pull request #165 from networm/07-git-tools_stashing-cleaning
Translate 07-git-tools stashing-cleaning
2 parents 3f28ba2 + 8464212 commit a583de8

File tree

1 file changed

+47
-47
lines changed

1 file changed

+47
-47
lines changed

book/07-git-tools/sections/stashing-cleaning.asc

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
[[_git_stashing]]
2-
=== Stashing and Cleaning
2+
=== 储藏与清理
33

4-
Often, when you’ve been working on part of your project, things are in a messy state and you want to switch branches for a bit to work on something else.
5-
The problem is, you don’t want to do a commit of half-done work just so you can get back to this point later.
6-
The answer to this issue is the `git stash` command.
4+
有时,当你在项目的一部分上已经工作一段时间后,所有东西都进入了混乱的状态,而这时你想要切换到另一个分支做一点别的事情。
5+
问题是,你不想仅仅因为过会儿回到这一点而为做了一半的工作创建一次提交。
6+
针对这个问题的答案是 `git stash` 命令。
77

8-
Stashing takes the dirty state of your working directory – that is, your modified tracked files and staged changes – and saves it on a stack of unfinished changes that you can reapply at any time.
8+
储藏会处理工作目录的脏的状态 - 即,修改的追踪文件与暂存改动 - 然后将未完成的修改保存到一个栈上,而你可以在任何时候重新应用这些改动。
99

10-
==== Stashing Your Work
10+
==== 储藏工作
1111

12-
To demonstrate, you’ll go into your project and start working on a couple of files and possibly stage one of the changes.
13-
If you run `git status`, you can see your dirty state:
12+
为了演示,进入项目并改动几个文件,然后可能暂存其中的一个改动。
13+
如果运行 `git status`,可以看到有改动的状态:
1414

1515
[source,console]
1616
----
@@ -27,8 +27,8 @@ Changes not staged for commit:
2727
modified: lib/simplegit.rb
2828
----
2929

30-
Now you want to switch branches, but you don’t want to commit what you’ve been working on yet; so you’ll stash the changes.
31-
To push a new stash onto your stack, run `git stash` or `git stash save`:
30+
现在想要切换分支,但是还不想要提交之前的工作;所以储藏修改。
31+
将新的储藏推送到栈上,运行 `git stash` `git stash save`
3232

3333
[source,console]
3434
----
@@ -39,7 +39,7 @@ HEAD is now at 049d078 added the index file
3939
(To restore them type "git stash apply")
4040
----
4141

42-
Your working directory is clean:
42+
工作目录是干净的了:
4343

4444
[source,console]
4545
----
@@ -48,8 +48,8 @@ $ git status
4848
nothing to commit, working directory clean
4949
----
5050

51-
At this point, you can easily switch branches and do work elsewhere; your changes are stored on your stack.
52-
To see which stashes you’ve stored, you can use `git stash list`:
51+
在这时,你能够轻易地切换分支并在其他地方工作;你的修改被存储在栈上。
52+
要查看储藏的东西,可以使用 `git stash list`
5353

5454
[source,console]
5555
----
@@ -59,10 +59,10 @@ stash@{1}: WIP on master: c264051 Revert "added file_size"
5959
stash@{2}: WIP on master: 21d80a5 added number to log
6060
----
6161

62-
In this case, two stashes were done previously, so you have access to three different stashed works.
63-
You can reapply the one you just stashed by using the command shown in the help output of the original stash command: `git stash apply`.
64-
If you want to apply one of the older stashes, you can specify it by naming it, like this: `git stash apply stash@{2}`.
65-
If you don’t specify a stash, Git assumes the most recent stash and tries to apply it:
62+
在本例中,有两个之前做的储藏,所以你接触到了三个不同的储藏工作。
63+
可以通过原来 stash 命令的帮助提示中的命令将你刚刚储藏的工作重新应用:`git stash apply`
64+
如果想要应用其中一个更旧的储藏,可以通过名字指定它,像这样:`git stash apply stash@{2}`
65+
如果不指定一个储藏,Git 认为指定的是最近的储藏:
6666

6767
[source,console]
6868
----
@@ -76,14 +76,14 @@ $ git stash apply
7676
#
7777
----
7878

79-
You can see that Git re-modifies the files you reverted when you saved the stash.
80-
In this case, you had a clean working directory when you tried to apply the stash, and you tried to apply it on the same branch you saved it from; but having a clean working directory and applying it on the same branch aren’t necessary to successfully apply a stash.
81-
You can save a stash on one branch, switch to another branch later, and try to reapply the changes.
82-
You can also have modified and uncommitted files in your working directory when you apply a stash – Git gives you merge conflicts if anything no longer applies cleanly.
79+
可以看到 Git 重新修改了当你保存储藏时撤消的文件。
80+
在本例中,当尝试应用储藏时有一个干净的工作目录,并且尝试将它应用在保存它时所在的分支;但是有一个干净的工作目录与应用在同一分支并不是成功应用储藏的充分必要条件。
81+
可以在一个分支上保存一个储藏,切换到另一个分支,然后尝试重新应用这些修改。
82+
当应用储藏时工作目录中也可以有修改与未提交的文件 - 如果有任何东西不能干净地应用,Git 会产生合并冲突。
8383

84-
The changes to your files were reapplied, but the file you staged before wasn’t restaged.
85-
To do that, you must run the `git stash apply` command with a `--index` option to tell the command to try to reapply the staged changes.
86-
If you had run that instead, you’d have gotten back to your original position:
84+
文件的改动被重新应用了,但是之前暂存的文件却没有重新暂存。
85+
想要那样的话,必须使用 `--index` 选项来运行 `git stash apply` 命令,来尝试重新应用暂存的修改。
86+
如果已经那样做了,那么你将回到原来的位置:
8787

8888
[source,console]
8989
----
@@ -101,8 +101,8 @@ $ git stash apply --index
101101
#
102102
----
103103

104-
The apply option only tries to apply the stashed work – you continue to have it on your stack.
105-
To remove it, you can run `git stash drop` with the name of the stash to remove:
104+
应用选项只会尝试应用暂存的工作 - 在堆栈上还有它。
105+
可以运行 `git stash drop` 加上将要移除的储藏的名字来移除它:
106106

107107
[source,console]
108108
----
@@ -114,13 +114,13 @@ $ git stash drop stash@{0}
114114
Dropped stash@{0} (364e91f3f268f0900bc3ee613f9f733e82aaed43)
115115
----
116116

117-
You can also run `git stash pop` to apply the stash and then immediately drop it from your stack.
117+
也可以运行 `git stash pop` 来应用储藏然后立即从栈上扔掉它。
118118

119-
==== Creative Stashing
119+
==== 创造性的储藏
120120

121-
There are a few stash variants that may also be helpful. The first option that is quite popular is the `--keep-index` option to the `stash save` command. This tells Git to not stash anything that you've already staged with the `git add` command.
121+
有几个储藏的变种可能也很有用。第一个非常流行的选项是 `stash save` 命令的 `--keep-index` 选项。它告诉 Git 不要储藏任何你通过 git add 命令已暂存的东西。
122122

123-
This can be really helpful if you've made a number of changes but want to only commit some of them and then come back to the rest of the changes at a later time.
123+
当你做了几个改动并只想提交其中的一部分,过一会儿再回来处理剩余改动时,这个功能会很有用。
124124

125125
[source,console]
126126
----
@@ -136,7 +136,7 @@ $ git status -s
136136
M index.html
137137
----
138138

139-
Another common thing you may want to do with stash is to stash the untracked files as well as the tracked ones. By default, `git stash` will only store files that are already in the index. If you specify `--include-untracked` or `-u`, Git will also stash any untracked files you have created.
139+
另一个经常使用储藏来做的事情是像储藏追踪文件一样储藏未追踪文件。默认情况下,`git stash` 只会储藏已经在索引中的文件。如果指定 `--include-untracked` `-u` 标记,Git 也会储藏任何创建的未追踪文件。
140140

141141
[source,console]
142142
----
@@ -153,7 +153,7 @@ $ git status -s
153153
$
154154
----
155155

156-
Finally, if you specify the `--patch` flag, Git will not stash everything that is modified but will instead prompt you interactively which of the changes you would like to stash and which you would like to keep in your working directly.
156+
最终,如果指定了 `--patch` 标记,Git 不会储藏所有修改过的任何东西,但是会交互式地提示哪些改动想要储藏、哪些改动需要保存在工作目录中。
157157

158158
[source,console]
159159
----
@@ -179,11 +179,11 @@ Saved working directory and index state WIP on master: 1b65b17 added the index f
179179
----
180180

181181

182-
==== Creating a Branch from a Stash
182+
==== 从储藏创建一个分支
183183

184-
If you stash some work, leave it there for a while, and continue on the branch from which you stashed the work, you may have a problem reapplying the work.
185-
If the apply tries to modify a file that you’ve since modified, you’ll get a merge conflict and will have to try to resolve it.
186-
If you want an easier way to test the stashed changes again, you can run `git stash branch`, which creates a new branch for you, checks out the commit you were on when you stashed your work, reapplies your work there, and then drops the stash if it applies successfully:
184+
如果储藏了一些工作,将它留在那儿了一会儿,然后继续在储藏的分支上工作,在重新应用工作时可能会有问题。
185+
如果应用尝试修改刚刚修改的文件,你会得到一个合并冲突并不得不解决它。
186+
如果想要一个轻松的方式来再次测试储藏的改动,可以运行 `git stash branch` 创建一个新分支,检出储藏工作时所在的提交,重新在那应用工作,然后在应用成功后扔掉储藏:
187187

188188
[source,console]
189189
----
@@ -203,20 +203,20 @@ Switched to a new branch "testchanges"
203203
Dropped refs/stash@{0} (f0dfc4d5dc332d1cee34a634182e168c4efc3359)
204204
----
205205

206-
This is a nice shortcut to recover stashed work easily and work on it in a new branch.
206+
这是在新分支轻松恢复储藏工作并继续工作的一个很不错的途径。
207207

208208
[[_git_clean]]
209-
==== Cleaning your Working Directory
209+
==== 清理工作目录
210210

211-
Finally, you may not want to stash some work or files in your working directory, but simply get rid of them. The `git clean` command will do this for you.
211+
对于工作目录中一些工作或文件,你想做的也许不是储藏而是移除。`git clean` 命令会帮你做这些事。
212212

213-
Some common reasons for this might be to remove cruft that has been generated by merges or external tools or to remove build artifacts in order to run a clean build.
213+
有一些通用的原因比如说为了移除由合并或外部工具生成的东西,或是为了运行一个干净的构建而移除之前构建的残留。
214214

215-
You'll want to be pretty careful with this command, since it's designed to remove files from your working directory that are not tracked. If you change your mind, there is often no retrieving the content of those files. A safer option is to run `git stash --all` to remove everything but save it in a stash.
215+
你需要谨慎地使用这个命令,因为它被设计为从工作目录中移除未被追踪的文件。如果你改变主意了,你也不一定能找回来那些文件的内容。一个更安全的选项是运行 `git stash --all` 来移除每一样东西并存放在栈中。
216216

217-
Assuming you do want to remove cruft files or clean your working directory, you can do so with `git clean`. To remove all the untracked files in your working directory, you can run `git clean -f -d`, which removes any files and also any subdirectories that become empty as a result. The `-f` means 'force' or "really do this".
217+
你可以使用`git clean`命令去除冗余文件或者清理工作目录。 使用`git clean -f -d`命令来移除工作目录中所有未追踪的文件以及空的子目录。`-f` 意味着 '强制' 或 “确定移除”。
218218

219-
If you ever want to see what it would do, you can run the command with the `-n` option, which means ``do a dry run and tell me what you _would_ have removed''.
219+
如果只是想要看看它会做什么,可以使用 `-n` 选项来运行命令,这意味着 ``做一次演习然后告诉你 _将要_ 移除什么''。
220220

221221
[source,console]
222222
----
@@ -225,7 +225,7 @@ Would remove test.o
225225
Would remove tmp/
226226
----
227227

228-
By default, the `git clean` command will only remove untracked files that are not ignored. Any file that matches a pattern in your `.gitignore` or other ignore files will not be removed. If you want to remove those files too, such as to remove all `.o` files generated from a build so you can do a fully clean build, you can add a `-x` to the clean command.
228+
默认情况下,`git clean` 命令只会移除没有忽略的未追踪文件。任何与 `.gitiignore` 或其他忽略文件中的模式匹配的文件都不会被移除。如果你也想要移除那些文件,例如为了做一次完全干净的构建而移除所有由构建生成的 `.o` 文件,可以给 clean 命令增加一个 `-x` 选项。
229229

230230
[source,console]
231231
----
@@ -244,9 +244,9 @@ Would remove test.o
244244
Would remove tmp/
245245
----
246246

247-
If you don't know what the `git clean` command is going to do, always run it with a `-n` first to double check before changing the `-n` to a `-f` and doing it for real. The other way you can be careful about the process is to run it with the `-i` or ``interactive'' flag.
247+
如果不知道 `git clean` 命令将会做什么,在将 `-n` 改为 `-f` 来真正做之前总是先用 `-n` 来运行它做双重检查。另一个小心处理过程的方式是使用 `-i` ``interactive'' 标记来运行它。
248248

249-
This will run the clean command in an interactive mode.
249+
这将会以交互模式运行 clean 命令。
250250

251251
[source,console]
252252
----
@@ -259,4 +259,4 @@ Would remove the following items:
259259
What now>
260260
----
261261

262-
This way you can step through each file individually or specify patterns for deletion interactively.
262+
这种方式下可以分别地检查每一个文件或者交互地指定删除的模式。

0 commit comments

Comments
 (0)