LoginSignup
7
6

More than 5 years have passed since last update.

git: マージコミットから前回の分岐点までの差分ログを取る

Posted at

TARGET_REV をマージコミットのリビジョンとした時、次のコマンドで差分を出力できる。

$ TARGET_REV=`git rev-parse --short HEAD`
$ git log --oneline `git show-branch --merge-base "${TARGET_REV}^1" "${TARGET_REV}^2"`..HEAD

解説

git rev-parse --short HEAD

HEAD(現在のリビジョン)のリビジョン番号を短いハッシュ値で出力する

git show-branch --merge-base "${TARGET_REV}^1" "${TARGET_REV}^2"

マージコミットの元となる2つのリビジョンの分岐点となるリビジョンを出力

git log --oneline {rev}..HEAD

{rev} から HEAD までのログを一行ずつで出力

応用

git log 以外にも git diff で使っても有用

$ git diff --stat `git show-branch --merge-base "${TARGET_REV}^1" "${TARGET_REV}^2"` HEAD
7
6
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
7
6