Skip to content

Commit 01c481b

Browse files
committed
Translate additional contents
1 parent 3ffdaeb commit 01c481b

File tree

9 files changed

+1126
-4
lines changed

9 files changed

+1126
-4
lines changed

book/07-git-tools/sections/advanced-merging.asc

Lines changed: 320 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,12 @@ simplegit.rb のステータスがおもしろいことになっています。
266266
つまり、このファイルを部分的にステージしたというわけです。
267267
この時点で対話的追加モードを抜けて `git commit` を実行すると、ステージした部分だけをコミットすることができます。
268268
269+
//////////////////////////
269270
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.
271+
//////////////////////////
272+
ファイルを部分的にステージするだけなら、対話的な追加モードに入る必要すらありません。`git add -p` や `git add --patch` をコマンドラインから実行すれば、同じ機能を呼び出せます。
270273
274+
//////////////////////////
271275
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.
276+
//////////////////////////
277+
また、このパッチモードを使って、ファイルの一部分だけをリセットすることもできます。その場合のコマンドは `reset --patch` です。同様に、部分的なチェックアウトは `checkout --patch` コマンドを、部分的に退避するなら `stash save --patch` コマンドを使います。各コマンドの詳細は、より高度な使い方に触れるときに併せて紹介します。

book/07-git-tools/sections/rerere.asc

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,45 @@
11
[[_rerere]]
22
=== Rerere
33

4+
//////////////////////////
45
The `git rerere` functionality is a bit of a hidden feature. The name stands for ``reuse recorded resolution'' and as the name implies, it allows you to ask Git to remember how you've resolved a hunk conflict so that the next time it sees the same conflict, Git can automatically resolve it for you.
6+
//////////////////////////
7+
`git rerere` コマンドはベールに包まれた機能といってもいいでしょう。これは ``reuse recorded resolution'' の略です。その名が示すとおり、このコマンドは、コンフリクトがどのように解消されたかを記録してくれます。そして、同じコンフリクトに次に出くわしたときに、自動で解消してくれるのです。
58

9+
//////////////////////////
610
There are a number of scenarios in which this functionality might be really handy. One of the examples that is mentioned in the documentation is if you want to make sure a long lived topic branch will merge cleanly but don't want to have a bunch of intermediate merge commits. With `rerere` turned on you can merge occasionally, resolve the conflicts, then back out the merge. If you do this continuously, then the final merge should be easy because `rerere` can just do everything for you automatically.
11+
//////////////////////////
12+
いくつもの場面で、この機能がとても役立つと思います。Git のドキュメントで挙げられている例は、長期にわたって開発が続いているトピックブランチを問題なくマージされるようにしておきたいけれど、そのためのマージコミットがいくつも生まれるような状況は避けたい、というものです。`rerere` を有効にした状態で、マージをときおり実行し、コンフリクトをそのたびに解消したうえで、マージを取り消してみてください。この手順を継続的に行っておけば、最終的なマージは容易なものになるはずです。`rerere` がすべてを自動で処理してくれるからです。
713

14+
//////////////////////////
815
This same tactic can be used if you want to keep a branch rebased so you don't have to deal with the same rebasing conflicts each time you do it. Or if you want to take a branch that you merged and fixed a bunch of conflicts and then decide to rebase it instead - you likely won't have to do all the same conflicts again.
16+
//////////////////////////
17+
リベースする度に同じコンフリクトを処理することなく、ブランチをリベースされた状態に保っておくときにもこの方法が使えます。あるいは、コンフリクトをすべて解消して、ようやっとマージし終えた後に、リベースを使うことに方針を変更したとしましょう。`rerere` を使えば、同じコンフリクトを再度処理せずに済みます。
918

19+
//////////////////////////
1020
Another situation is where you merge a bunch of evolving topic branches together into a testable head occasionally, as the Git project itself often does. If the tests fail, you can rewind the merges and re-do them without the topic branch that made the tests fail without having to re-resolve the conflicts again.
21+
//////////////////////////
22+
その他にも、開発中のトピックブランチをいくつもまとめてマージして、テスト可能な HEAD を生成するとき(Git 本体のプロジェクトでよく行われています)にもこのコマンドが使えます。テストが失敗したら、マージを取り消したうえで失敗の原因となったブランチを除外してからテストを再実行するわけですが、`rerere` を使えばその際にコンフリクトを解消する必要がなくなるのです。
1123

24+
//////////////////////////
1225
To enable the `rerere` functionality, you simply have to run this config setting:
26+
//////////////////////////
27+
`rerere` を有効にするには、以下の設定コマンドを実行しましょう。
1328

1429
[source,console]
1530
----
1631
$ git config --global rerere.enabled true
1732
----
1833

34+
//////////////////////////
1935
You can also turn it on by creating the `.git/rr-cache` directory in a specific repository, but the config setting is clearer and it can be done globally.
36+
//////////////////////////
37+
該当のリポジトリに `.git/rr-cache` というディレクトリを作成しても `rerere` は有効になりますが、設定するほうがわかりやすいでしょう。設定であれば、全リポジトリに適用することもできます。
2038

39+
//////////////////////////
2140
Now let's see a simple example, similar to our previous one. Let's say we have a file that looks like this:
41+
//////////////////////////
42+
では実際の例を見てみましょう。以前使ったような単純な例です。以下のようなファイルがあったとします。
2243

2344
[source,console]
2445
----
@@ -29,11 +50,17 @@ def hello
2950
end
3051
----
3152

53+
//////////////////////////
3254
In one branch we change the word ``hello'' to ``hola'', then in another branch we change the ``world'' to ``mundo'', just like before.
55+
//////////////////////////
56+
今いるブランチではこのファイルの ``hello'' という単語を ``hola'' に変更し、別のブランチでは ``world'' を ``mundo'' に変更したとします。前回と同様ですね。
3357

3458
image::images/rerere1.png[]
3559

60+
//////////////////////////
3661
When we merge the two branches together, we'll get a merge conflict:
62+
//////////////////////////
63+
これら2つのブランチをマージしようとすると、コンフリクトが発生します。
3764

3865
[source,console]
3966
----
@@ -44,7 +71,10 @@ Recorded preimage for 'hello.rb'
4471
Automatic merge failed; fix conflicts and then commit the result.
4572
----
4673

74+
//////////////////////////
4775
You should notice the new line `Recorded preimage for FILE` in there. Otherwise it should look exactly like a normal merge conflict. At this point, `rerere` can tell us a few things. Normally, you might run `git status` at this point to see what all conflicted:
76+
//////////////////////////
77+
コマンド出力に `Recorded preimage for FILE` という見慣れない行があるのに気づかれたでしょう。他の部分は、よくあるコンフリクトのメッセージと変わりありません。この時点で、`rerere` からわかることがいくつかあります。こういった場合、いつもであれば以下のように `git status` を実行し、何がコンフリクトしているのかを確認するものです。
4878

4979
[source,console]
5080
----
@@ -58,15 +88,21 @@ $ git status
5888
#
5989
----
6090

91+
//////////////////////////
6192
However, `git rerere` will also tell you what it has recorded the pre-merge state for with `git rerere status`:
93+
//////////////////////////
94+
ですが、ここで `git rerere status` を実行すると、どのファイルのマージ前の状態が `git rerere` によって保存されたかがわかります。
6295

6396
[source,console]
6497
----
6598
$ git rerere status
6699
hello.rb
67100
----
68101

102+
//////////////////////////
69103
And `git rerere diff` will show the current state of the resolution - what you started with to resolve and what you've resolved it to.
104+
//////////////////////////
105+
更に、`git rerere diff` を実行すると、コンフリクト解消の状況がわかります。具体的には、着手前がどういう状態であったか、どういう風に解消したのか、がわかります。
70106

71107
[source,console]
72108
----
@@ -89,7 +125,10 @@ $ git rerere diff
89125
end
90126
----
91127

128+
//////////////////////////
92129
Also (and this isn't really related to `rerere`), you can use `ls-files -u` to see the conflicted files and the before, left and right versions:
130+
//////////////////////////
131+
また(`rerere` 特有の話ではありませんが)、コンフリクトしているファイルと、そのファイルの3バージョン(マージ前・コンフリクトマーカー左向き・コンフリクトマーカー右向き)が `ls-files -u` を使うとわかります。
93132

94133
[source,console]
95134
----
@@ -99,7 +138,10 @@ $ git ls-files -u
99138
100644 54336ba847c3758ab604876419607e9443848474 3 hello.rb
100139
----
101140

141+
//////////////////////////
102142
Now you can resolve it to just be `puts 'hola mundo'` and you can run the `rerere diff` command again to see what rerere will remember:
143+
//////////////////////////
144+
さて、このコンフリクトは `puts 'hola mundo'` と修正しておきます。そして、 もう一度 `rerere diff` コマンドを実行すると、rerere が記録する内容を確認できます。
103145

104146
[source,console]
105147
----
@@ -119,9 +161,15 @@ $ git rerere diff
119161
end
120162
----
121163

164+
//////////////////////////
122165
So that basically says, when Git sees a hunk conflict in a `hello.rb` file that has ``hello mundo'' on one side and ``hola world'' on the other, it will resolve it to ``hola mundo''.
166+
//////////////////////////
167+
これを記録したということは、`hello.rb` に同じコンフリクト(一方は ``hello mundo'' でもう一方が ``hola world'')が見つかった場合、自動的に ``hola mundo'' に修正されるということになります。
123168

169+
//////////////////////////
124170
Now we can mark it as resolved and commit it:
171+
//////////////////////////
172+
では、この変更内容をコミットしましょう。
125173

126174
[source,console]
127175
----
@@ -131,19 +179,28 @@ Recorded resolution for 'hello.rb'.
131179
[master 68e16e5] Merge branch 'i18n'
132180
----
133181

182+
//////////////////////////
134183
You can see that it "Recorded resolution for FILE".
184+
//////////////////////////
185+
コマンド出力から、Git が "Recorded resolution for FILE"、FILE のコンフリクト解消方法を記録したようです。
135186

136187
image::images/rerere2.png[]
137188

189+
//////////////////////////
138190
Now, let's undo that merge and then rebase it on top of our master branch instead. We can move our branch back by using `reset` as we saw in <<_git_reset>>.
191+
//////////////////////////
192+
ではここで、このマージを取り消して、master ブランチにリベースしてみましょう。<<_git_reset>> で紹介したとおり、ブランチを巻き戻すには `reset` を使います。
139193

140194
[source,console]
141195
----
142196
$ git reset --hard HEAD^
143197
HEAD is now at ad63f15 i18n the hello
144198
----
145199

200+
//////////////////////////
146201
Our merge is undone. Now let's rebase the topic branch.
202+
//////////////////////////
203+
マージが取り消されました。続いてトピックブランチをリベースしてみます。
147204

148205
[source,console]
149206
----
@@ -162,7 +219,10 @@ Failed to merge in the changes.
162219
Patch failed at 0001 i18n one word
163220
----
164221

222+
//////////////////////////
165223
Now, we got the same merge conflict like we expected, but take a look at the `Resolved FILE using previous resolution` line. If we look at the file, we'll see that it's already been resolved, there are no merge conflict markers in it.
224+
//////////////////////////
225+
予想どおり、マージコンフリクトが発生しました。一方、`Resolved FILE using previous resolution` というメッセージも出力されています。該当のファイルを確認してみてください。コンフリクトはすでに解消されていて、コンフリクトを示すマーカーは挿入されていないはずです。
166226

167227
[source,console]
168228
----
@@ -174,7 +234,10 @@ def hello
174234
end
175235
----
176236

237+
//////////////////////////
177238
Also, `git diff` will show you how it was automatically re-resolved:
239+
//////////////////////////
240+
また、ここで `git diff` を実行すると、コンフリクトの再解消がどのように自動処理されたかがわかります。
178241

179242
[source,console]
180243
----
@@ -195,7 +258,10 @@ index a440db6,54336ba..0000000
195258

196259
image::images/rerere3.png[]
197260

261+
//////////////////////////
198262
You can also recreate the conflicted file state with the `checkout` command:
263+
//////////////////////////
264+
なお、`checkout` コマンドを使うと、ファイルがコンフリクトした状態を再現できます。
199265

200266
[source,console]
201267
----
@@ -212,8 +278,11 @@ def hello
212278
end
213279
----
214280

281+
//////////////////////////
215282
We saw an example of this in <<_advanced_merging>>.
216283
For now though, let's re-resolve it by just running `rerere` again:
284+
//////////////////////////
285+
これは <<_advanced_merging>> で使用した例と同じ内容ですが、ここでは `rerere` を使ってコンフリクトをもう一度解消してみましょう。
217286

218287
[source,console]
219288
----
@@ -227,7 +296,10 @@ def hello
227296
end
228297
----
229298

299+
//////////////////////////
230300
We have re-resolved the file automatically using the `rerere` cached resolution. You can now add and continue the rebase to complete it.
301+
//////////////////////////
302+
`rerere` がキャッシュした解消方法で、再処理が自動的に行われたようです。結果をインデックスに追加して、リベースを先に進めましょう。
231303

232304
[source,console]
233305
----
@@ -236,4 +308,7 @@ $ git rebase --continue
236308
Applying: i18n one word
237309
----
238310

311+
//////////////////////////
239312
So, if you do a lot of re-merges, or want to keep a topic branch up to date with your master branch without a ton of merges, or you rebase often, you can turn on `rerere` to help your life out a bit.
313+
//////////////////////////
314+
マージの再実行を何度も行うことがある、頻繁に master ブランチをマージせずにトピックブランチを最新の状態に保ちたい、リベースをよく行う……いずれかに当てはまる場合は `rerere` を有効にしておきましょう。日々の生活がちょっとだけ楽になると思います。

0 commit comments

Comments
 (0)