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.
The most basic and powerful tool to do this is the git log command. By default, with no arguments, git log lists the commits made in that repository in reverse chronological order — that is, the most recent commits show up first.
The command for that would be git log –oneline -n where n represents the number up to which commit you to want to see the logs.
A merge commit is a commit with two1 parents. This means that git log and git show would have to run two git diff commands. 2. And in fact, git show does run two diffs, but then—by default—turns them into a combined diff, which shows only those files whose merge-commit version differs from both parents.
1 answer. You just need to check the length of the `parents`. If there are two or more commits, it's a merge commit, otherwise it's a regular commit.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With