Skip to content

Commit 66c66e5

Browse files
committed
Translate additional contents
1 parent c55b2c6 commit 66c66e5

File tree

6 files changed

+324
-1
lines changed

6 files changed

+324
-1
lines changed

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/revision-selection.asc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ Generally, eight to ten characters are more than enough to be unique within a pr
9393
//////////////////////////
9494
ひとつのプロジェクト内での一意性を確保するには、普通は 8 文字から 10 文字もあれば十分すぎることでしょう。
9595
96+
//////////////////////////
9697
As an example, the Linux kernel, which is a pretty large project with over 450k commits and 3.6 million objects, has no two objects whose SHAs overlap more than the first 11 characters.
98+
//////////////////////////
99+
参考までに数字を挙げておきます。Linux カーネルはコミット数45万、オブジェクト数360万という巨大プロジェクトですが、SHA の最初の12桁が同じになるオブジェクトは存在しません。
97100
98101
[NOTE]
99102
//////////////////////////

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

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
[[_searching]]
2+
//////////////////////////
23
=== Searching
4+
//////////////////////////
5+
=== 検索
36
7+
//////////////////////////
48
With just about any size codebase, you'll often need to find where a function is called or defined, or find the history of a method. Git provides a couple of useful tools for looking through the code and commits stored in it's database quickly and easily. We'll go through a few of them.
9+
//////////////////////////
10+
コード量の大小を問わず、関数の参照位置・定義やメソッドの変更履歴を確認したくなることはよくあります。Git には便利なツールがいくつも用意されていて、コードやコミット履歴の確認が簡単にできるようになっています。具体的な方法をいくつか見ていきましょう。
511
612
[[_git_grep]]
713
==== Git Grep
814
15+
//////////////////////////
916
Git ships with a command called `grep` that allows you to easily search through any committed tree or the working directory for a string or regular expression. For these examples, we'll look through the Git source code itself.
17+
//////////////////////////
18+
Git に付属する `grep` コマンドを使うと、コミット済みのツリーや作業ディレクトリが簡単に検索(文字列・正規表現)できます。使い方の説明を兼ねて、Git のソースコードを覗いてみることにしましょう。
1019
20+
//////////////////////////
1121
By default, it will look through the files in your working directory. You can pass `-n` to print out the line numbers where Git has found matches.
22+
//////////////////////////
23+
このコマンドはデフォルトでは作業ディレクトリを検索します。`-n` オプションと一緒に使うと、検索条件とマッチした行の番号も表示してくれます。
1224
1325
[source,console]
1426
----
@@ -25,9 +37,16 @@ git-compat-util.h:721:struct tm *git_gmtime_r(const time_t *, struct tm *);
2537
git-compat-util.h:723:#define gmtime_r git_gmtime_r
2638
----
2739
40+
//////////////////////////
2841
There are a number of interesting options you can provide the `grep` command.
42+
//////////////////////////
43+
その他にも、興味深いオプションがこのコマンドにはいくつも用意されています。
2944
45+
46+
//////////////////////////
3047
For instance, instead of the previous call, you can have Git summarize the output by just showing you which files matched and how many matches there were in each file with the `--count` option:
48+
//////////////////////////
49+
上記の実行例とは違い、コマンド出力を Git に要約させることもできます。例えば、検索にマッチしたファイルの名前とマッチ回数を表示させるには、`--count` オプションを使います。
3150
3251
[source,console]
3352
----
@@ -39,7 +58,10 @@ date.c:2
3958
git-compat-util.h:2
4059
----
4160
61+
//////////////////////////
4262
If you want to see what method or function it thinks it has found a match in, you can pass `-p`:
63+
//////////////////////////
64+
検索にマッチした結果からメソッドや関数と思われるものだけを確認したい場合は、`-p` オプションを使いましょう。
4365
4466
[source,console]
4567
----
@@ -50,11 +72,20 @@ date.c=static int match_digit(const char *date, struct tm *tm, int *offset, int
5072
date.c: if (gmtime_r(&time, tm)) {
5173
----
5274
75+
//////////////////////////
5376
So here we can see that `gmtime_r` is called in the `match_multi_number` and `match_digit` functions in the date.c file.
77+
//////////////////////////
78+
この例では、`gmtime_r` が date.c ファイルにある関数 `match_multi_number` と `match_digit` から呼び出されていることがわかります。
5479
80+
//////////////////////////
5581
You can also look for complex combinations of strings with the `--and` flag, which makes sure that multiple matches are in the same line. For instance, let's look for any lines that define a constant with either the strings ``LINK'' or ``BUF_MAX'' in them in the Git codebase in an older 1.8.0 version.
82+
//////////////////////////
83+
また、文字列の複雑な組み合わせを探したい場合は `--and` オプションを使いましょう。検索条件がすべて同一行に含まれている行だけを返すためのオプションです。例として、文字列 ``LINK'' か ``BUF_MAX'' を含む定数が記述されている行を、Git の古いバージョン 1.8.0 から探してみます。
5684
85+
//////////////////////////
5786
Here we'll also use the `--break` and `--heading` options which help split up the output into a more readable format.
87+
//////////////////////////
88+
なお、この例では `--break` と `--heading` のオプションも使っています。出力を分割して読みやすくするためです。
5889
5990
[source,console]
6091
----
@@ -81,13 +112,26 @@ v1.8.0:zlib.c
81112
31:#define ZLIB_BUF_MAX ((uInt) 1024 * 1024 * 1024) /* 1GB */
82113
----
83114
115+
//////////////////////////
84116
The `git grep` command has a few advantages over normal searching commands like `grep` and `ack`. The first is that it's really fast, the second is that you can search through any tree in Git, not just the working directory. As we saw in the above example, we looked for terms in an older version of the Git source code, not the version that was currently checked out.
117+
//////////////////////////
118+
`grep` や `ack` のような他の検索用コマンドと比較すると、`git grep` コマンドには利点がふたつあります。とても早く動作することと、作業ディレクトリだけでなくコミット済みの全ツリーが検索対象であることです。上記の例ではその利点を示すために、検索対象を古いバージョンの Git のソースコードとし、チェックアウトされたバージョンのものにはしませんでした。
85119
120+
//////////////////////////
86121
==== Git Log Searching
122+
//////////////////////////
123+
==== Git ログの検索
87124
125+
//////////////////////////
88126
Perhaps you're looking not for **where** a term exists, but **when** it existed or was introduced. The `git log` command has a number of powerful tools for finding specific commits by the content of their messages or even the content of the diff they introduce.
127+
//////////////////////////
128+
場合によっては、探しているのは語句の **所在** ではなく、語句が存在した・追加された **時期**、ということもあるでしょう。`git log` コマンドの強力なオプションを使うと、コミットメッセージの内容やコミットごとの差分をもとに、特定のコミットを絞り込めます。
129+
89130
131+
//////////////////////////
90132
If we want to find out for example when the `ZLIB_BUF_MAX` constant was originally introduced, we can tell Git to only show us the commits that either added or removed that string with the `-S` option.
133+
//////////////////////////
134+
ここでは、定数 `ZLIB_BUF_MAX` が追加された時期を調べてみましょう。その文字列が追加、あるいは削除されたコミットだけを表示するには、`-S` オプションを用います。
91135
92136
[source,console]
93137
----
@@ -96,15 +140,30 @@ e01503b zlib: allow feeding more than 4GB in one go
96140
ef49a7a zlib: zlib can only process 4GB at a time
97141
----
98142
143+
//////////////////////////
99144
If we look at the diff of those commits we can see that in `ef49a7a` the constant was introduced and in `e01503b` it was modified.
145+
//////////////////////////
146+
これらのコミットの差分を見てみると、コミット `ef49a7a` でこの定数が追加され、コミット `e01503b` でそれが変更されたことがわかります。
100147
148+
//////////////////////////
101149
If you need to be more specific, you can provide a regular expression to search for with the `-G` option.
150+
//////////////////////////
151+
より詳しく調べたいのなら、`-G` オプションをつけましょう。検索に正規表現が使えるようになります。
102152
153+
//////////////////////////
103154
===== Line Log Search
155+
//////////////////////////
156+
===== ログの行指向検索
104157
158+
//////////////////////////
105159
Another fairly advanced log search that is insanely useful is the line history search. This is a fairly recent addition and not very well known, but it can be really helpful. It is called with the `-L` option to `git log` and will show you the history of a function or line of code in your codebase.
160+
//////////////////////////
161+
一歩進んだログ検索の方法をもうひとつ見ておきましょう。履歴を行指向で検索するという、ものすごく便利な方法です。最近になって Git に追加された機能であまり知られていませんが、本当に便利です。`git log` コマンドに `-L` オプションをつけると行指向検索が有効になり、指定した行(関数など)の履歴を確認できます。
106162
163+
//////////////////////////
107164
For example, if we wanted to see every change made to the function `git_deflate_bound` in the `zlib.c` file, we could run `git log -L :git_deflate_bound:zlib.c`. This will try to figure out what the bounds of that function are and then look through the history and show me every change that was made to the function as a series of patches back to when the function was first created.
165+
//////////////////////////
166+
ここでは仮に、`zlib.c` ファイルにある `git_deflate_bound` 関数の変更履歴を確認したいとしましょう。用いるコマンドは `git log -L :git_deflate_bound:zlib.c` です。これを実行すると、指定された関数の定義範囲がまずは推測されます。そして、その範囲の全変更履歴をパッチの形でひとつずつ、関数が追加されたときの履歴にまでさかのぼって表示します。
108167
109168
[source,console]
110169
----
@@ -144,4 +203,7 @@ diff --git a/zlib.c b/zlib.c
144203
+
145204
----
146205
206+
//////////////////////////
147207
If Git can't figure out how to match a function or method in your programming language, you can also provide it a regex. For example, this would have done the same thing: `git log -L '/unsigned long git_deflate_bound/',/^}/:zlib.c`. You could also give it a range of lines or a single line number and you'll get the same sort of output.
208+
//////////////////////////
209+
検索対象のコードで用いられているプログラミング言語によっては、 Git が関数やメソッドの定義範囲を絞り込めないことがあります。そんな場合は、正規表現を使いましょう。上記の例でいえば `git log -L '/unsigned long git_deflate_bound/',/^}/:zlib.c` はまったく同じ結果を出力します。また、行番号で検索対象を指定(単一行の指定、複数行で範囲指定の両方が可能)しても、同じような結果が得られます。

0 commit comments

Comments
 (0)