LoginSignup
2
0

More than 1 year has passed since last update.

git log の "--ancestry-path" と "--first-parent" を図とコマンドで確認する

Last updated at Posted at 2022-02-05

"--ancestry-path"

以下説明がイマイチ理解しづらかったので、コマンドで確認してみたメモ。

表示するコミットの範囲(例えば、「commit1..commit2」または「commit2 ^ commit1」)が指定されている場合、「commit1」と「commit2」の間の祖先チェーンに直接存在するコミット、つまり、「commit1」の子孫と「commit2」の祖先の両方であるコミットのみを表示します。
https://tracpath.com/docs/git-log/

下準備

  • master ブランチから master1 / master2 ブランチを切って、また合流する

イメージ図

image.png

コマンド

# master ブランチで最初のコミット
% git init
% git commit --allow-empty -m "Initial Commit"

# master1ブランチを切ってコミットを作る
% git ch -b master1
% touch master1; git add . ; git commit -m "master1-1"
% touch master1-2; git add . ; git commit -m "master1-2"

# master ブランチに戻って master2 ブランチを切ってコミット
% git ch master
% git ch -b master1
% touch master2; git add . ; git commit -m "master2-1"
% touch master2-2; git add . ; git commit -m "master2-2"

# master ブランチに戻ってコミット
% git ch master
% touch master; git add . ; git commit -m "master"

# マージ
% git merge master1
% git merge master2

例1: 頭から最後まで指定

分岐したもの全てが条件に当てはまるので全て表示される

git log --oneline --ancestry-path A..H

image.png

例2: 分岐したところから最後まで指定

分岐したところから最後まで。異なる分岐の方のコミットは入らない。

git log --oneline --ancestry-path C..H

image.png

"--first-parent"

下準備は上記の引き続き。
master ブランチでコミットしたやつだけを表示。
master1 や master2 ブランチでコミットされたものは表示されない

image.png

master1 の場合。

image.png

参考

https://git-scm.com/docs/git-log
https://amzn.to/3IZzWyM

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0