Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.

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
mather314
元数学専攻のエンジニア。Web系のアプリケーション開発がメインだが、HTMLやCSSよりはバックエンドロジックの分析などが得意。Haskell, Scala, Elmなどを嗜む程度に。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした