Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
7
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

@mather314

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

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
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
7
Help us understand the problem. What are the problem?