Git log foo..bar — how to see *merge dates* for changesets

git

Is it possible to get 'git log' to give the date when a changeset landed on a branch rather than the date when the changeset was created? 'git log –graph' (example truncated output below) gives me much of what I want, but it still prints the dates when the individual changesets were created rather than when they were merged into this branch.

*   commit 7e8d68fc58b915cc17bca41be833c4f7a062cd3c
|\  Merge: 1b4f10d af0dcdd
| | Date:   Wed Apr 25 17:40:16 2012 +0100
| |     Merge branch 'foo'
| * commit af0dcdd078197a852fcfad11c5111aa11579aa05
| | Date:   Wed Apr 25 17:36:50 2012 +0100
| |     t2: adding lorem ipsum again
| * commit 569f5de0eb40cbf198771812f9b099cf71b5b056
| | Date:   Wed Apr 25 17:36:36 2012 +0100
| |     t1: adding lorem ipsum
* | commit 1b4f10d3eea7c9c6304f7b1fd41818b932e4dad0
| | Date:   Wed Apr 25 17:38:24 2012 +0100
| |     t4: fi fo fa fum x 2
* | commit d25fa0359fbe655b6a4adeb6225ac283b3543ece
|/  Date:   Wed Apr 25 17:38:10 2012 +0100
|       t3: fi fo fa fum
* commit d3239b3e327f740fc7194ecf164538361f715ab5
  Date:   Wed Apr 25 17:34:50 2012 +0100

In the above the output is from the master branch. t1 and t2 were created on the foo branch; t3 & t4 were created on bar. Then bar was merged into master followed by merging foo into master.

Best Solution

You can see part of the answer: When branch foo was merged into master, it created a new commit (7e8d68) with two parents.

But when bar was merged into master, it was a fast-forward merge. That is, all of the commits on bar were newer than the newest work on master, so they could just be tacked onto the end.

That makes for a simpler layout, and so it's the default behavior. But it leaves no record of the merge -- as far as your history is concerned, it will look like those commits were done on master in the first place.

To get around that, it's possible to tell git explicitly to avoid fast-forward merges: that is, every single merge should result in a merge commit with two parents, even if a fast-forward merge would be possible. To do that, just use the --no-ff flag on the git merge command.

Unfortunately, because that's a change in merging behavior rather than logging behavior, you won't be able to do it retroactively -- the information from your previous fast-forward merges doesn't exist, so there's no way to get git log to display it.