0

I need to get git commits from within a specific range, so I've been using

git log old_commit..new_commit

It works great apart when there was only 1 new commit added, and that old and new commit were either git commit -m '' or git pull

For example:

commit XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Merge: XXXXXXY XXXXXXZ
Author: name <name@domain.com>
Date:   Fri Nov 20 11:45:33 2015 +0200

    Merge branch 'master' of xxxxxx.xx:xxxxxxx

commit XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXY
Author: name <name@domain.com>
Date:   Fri Nov 20 11:45:05 2015 +0200

    some commit message here

(Mind you the sequence could be in a different order - merge first then commit)

My point is, when I do:

git log XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXY..XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX  

it behaves unexpectedly and instead of 1 (last) commit, it outputs a lot more others.

Am I doing something wrong? Are merges and commits considered as one or something?

Arno
  • 356
  • 5
  • 18
  • 1
    Take a look [here](http://stackoverflow.com/questions/462974/what-are-the-differences-between-double-dot-and-triple-dot-in-git-com) – ckruczek Nov 24 '15 at 06:54

1 Answers1

1

old..new actually means, literally, All commits reachable by new that are not reachable by old. You can replace reachable here by is an ancestor of.

Since your new is a merge commit, the output of old..new will be all the commits that are not ancestors of old.

enter image description here

In the above illustration, commits point to their parents (i.e. the direction of arrows is child --> parent)

Sébastien Dawans
  • 4,537
  • 1
  • 20
  • 29
  • So in order to ignore E, F and G in the example, i.e. contents of a branch that was merged, you can add option `--first-parent`. This filters out commits that belong to other branches in case of non-fast-forward merges and only shows the merge commit. – sendaran Nov 24 '15 at 08:33