Git の「バウンダリーコミット」とは

Git

Git のコマンドの説明を読んでいると、ときどき「バウンダリーコミット」( boundary commit )ということばが出てくることがあります。

「バウンダリーコミット」。 パッと検索してみましたが日本語での説明がなかなか見つからないので、私が理解している範囲のことをかんたんにまとめておきます。

「バウンダリーコミット」の使われどころ

まずはこのことばが使われている具体的な場面を見ていきます。

git log

例えば、 git log の場合はこんな感じです。

--boundary Output excluded boundary commits. Boundary commits are prefixed with -.

git blame

git blame の場合だとこんな感じ。

-b Show blank SHA-1 for boundary commits. This can also be controlled via the blame.blankboundary config option.

--abbrev=<n> Instead of using the default 7+1 hexadecimal digits as the abbreviated object name, use <n>+1 digits. Note that 1 column is used for a caret to mark the boundary commit.

「バウンダリーコミット」とは

「バウンダリーコミット」は何かというと、要は、コミットログなどを表示する際に「境界線となっているコミット」のことのようです。

具体例を見てみましょう。

例えば、 git log -n 3 と打つと、通常 3 件のログが表示されます。 これに --boundary オプションを付けて git log -n 3 --boundary とすると、バウンダリーコミット(境界となるコミット)も表示してくれます。 結果として、 -n 3 と指定しているのに 4 件のコミットログが表示されることになります。

こんな感じです。

$ git log -n 3 --boundary
commit 3889ac827f969af4c3d08c06e8f2cc2c613eef8c
Author: Goto Hayato <example@example.com>
Date:   Sun Oct 22 21:13:46 2017 +0900

    コミットだね。

commit 04df4398ee13392bfd7693ce76d0ca04018f51b2
Author: Goto Hayato <example@example.com>
Date:   Sun Oct 22 00:05:46 2017 +0900

    コミットだよ。

commit 5b100525546ac987f75a06e28e49b128571641ce
Author: Goto Hayato <example@example.com>
Date:   Sun Oct 22 00:02:04 2017 +0900

    コミットかな。

commit - ef0f963a6c3dd5b7486e15dd298860405699d5e8
Author: Goto Hayato <example@example.com>
Date:   Sat Oct 21 23:24:35 2017 +0900

    コミットかしら。

いちばん下のコミットがバウンダリーコミットです。 上の --boundary の説明のとおり、バウンダリーコミットにはハッシュ値の前に - のマークが付いていることが確認できます。

git blame の場合も git log と考え方は同じで、「バウンダリーコミット」は範囲の中でいちばん最初のコミットを指すようです。 --root オプションなどをつけたりしなければ、イニシャルコミットがバウンダリーコミットとみなされます。

上の -abbrev の説明のとおり、バウンダリーコミットの先頭にはキャレット文字 ^ が付いており他とひと目で区別がつきます。

$ git blame index.php
^38a2fc9 (User Goto 2015-02-22 22:03:47 +0900  1) <?php
^38a2fc9 (User Goto 2015-02-22 22:03:47 +0900  2)
^38a2fc9 (User Goto 2015-02-22 22:03:47 +0900  3) /**
^38a2fc9 (User Goto 2015-02-22 22:03:47 +0900  4)  * @file

...

git blame に上の -b オプションをつけるとハッシュ値の部分が空文字列になります。

$ git blame index.php
         (User Goto 2015-02-22 22:03:47 +0900  1) <?php
         (User Goto 2015-02-22 22:03:47 +0900  2)
         (User Goto 2015-02-22 22:03:47 +0900  3) /**
         (User Goto 2015-02-22 22:03:47 +0900  4)  * @file

...

以上です。

一度わかるとどうということはないのですが、聞き慣れていないと「え?バウンダリー?」となりますね。

参考


アバター
後藤隼人 ( ごとうはやと )

ソフトウェア開発やマーケティング支援などをしています。詳しくはこちら