64

I use a fairly complex git-log command involving --date-order to get an overview of my repository's status; but unfortunately, --date-order seems to use the committer date, not the author date. That means that each time I bring my topic branches up to date by rebasing them onto the current upstream, I lose the helpful chronological ordering in my git-log of relative commits in my topic branches (that is, each branch becomes a single long line, because all of its commits got rebased to sequential and nearly-identical committer timestamps.)

If I could get git-log to order commits by the author timestamp instead of the committer timestamp, this would be solved. Does anybody know of a way to do that?


For those visiting this from Google results, you may want to look into josephdpurcell's solution (and in-depth blog post!), below. It's quite excellent, if you're looking for standard git-log style output, multi-line, with detailed messages about each commit.

Unfortunate, I now need to amend this question, because I'm an idiot and didn't provide more specific information about my use-case: I use git-log in “--graph mode,” and I need to make git-log itself operate in author-date-order. As far as I've been able to ascertain, this is completely impossible to do from outside git-log, because git-log itself handles the graph ordering and printing.

A script, or patch for git-log, may be necessary, it seems. I'll leave this open until somebody can either 1. write such a script, or 2. we can talk the git authors into including a --author --date-order combination of flags. (=


For reference, here's what my current glog function's output looks like, and what I need to re-order:

glog output

Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
ELLIOTTCABLE
  • 17,185
  • 12
  • 62
  • 78

4 Answers4

81

git version 1.8.4 added an --author-date-order argument to git log; according to the release notes, "the output is topologically sorted and commits in parallel histories are shown intermixed together based on the author timestamp."

M Somerville
  • 4,499
  • 30
  • 38
  • 3
    Heh. I actually did a lot of the work here (after posting this question), but didn't realize it'd ever gotten cleaned up and mainlined. Cool! Thanks for the heads-up. I'll test that it indeed solves my actual, original problem, and then probably accept this answer. – ELLIOTTCABLE Sep 19 '13 at 07:21
  • 2
    I had the same (or very similar) issue, and adding this to my log alias makes it far more readable now. Thanks! – zshift Jun 06 '17 at 19:40
24

Okay, this took me a very long time to figure out (details). In short, I found many examples that were either incomplete or incorrect. The following command does what I think you would expect:

$ git log --pretty="format:%at %C(yellow)commit %H%Creset\nAuthor: %an <%ae>\nDate: %aD\n\n %s\n" | sort -r | cut -d" " -f2- | sed -e "s/\\\n/\\`echo -e '\n\r'`/g" | tr -d '\15\32' | less -R

You can find this script and others in Git Extras on GitHub.

josephdpurcell
  • 1,157
  • 3
  • 16
  • 34
  • +1 Yes! simple and sweet. And also +1 for the whole blog explanation. – Alexander Bird Mar 14 '13 at 21:00
  • 1
    And if you want to turn this into an alias: `alias prettylog=git log --pretty='format:%at %C(yellow)commit %H%Creset\nAuthor: %an <%ae>\nDate: %aD\n\n %s\n' | sort -r | cut -d' ' -f2- | sed -e 's/\\\n/\\`echo -e '\n\r'\`/g' | tr -d '\15\32' | less -R"` – Druska Apr 15 '13 at 19:20
  • I was actually looking to a precursor from your solution (I'm setting up a one-line log; so all the multi-line and `tr` nonesense was irrelevant to me) … but since you condensed all your research into a blog post (you sly devil!), I was able to use one of your previous incarnations. Best response I've ever gotten out of S.O.; wish I could upvote you twice. (= – ELLIOTTCABLE May 28 '13 at 09:04
  • 2
    I got super-excited about this solution, until I realized it doesn't support `--graph`, which completely defeats the purpose for me. Without `--graph`, I can't see the *structure* of my history, which makes `git-log` useless to me as a whole. >: – ELLIOTTCABLE May 28 '13 at 09:21
12

--date-order/--topo-order really just controls the ordering of commits in a revision list when you are viewing multiple branches running alongside another. The "x is-a-parent of y" relationship is always respected, even if your committer/authoring timestamp is in the distant past or future.

You'd need something like git log --pretty="format:%at %H" | sort -g and then feed the hashes back into git log.

jørgensen
  • 10,149
  • 2
  • 20
  • 27
2

Building off of what jørgensen suggested there is a "one-liner" solution that may give you what you are looking for. Formatted here for easier viewing. Improvements are welcomed!

SORTED_GIT_LOGS=$(git log --pretty="format:%at %H" | sort -g | cut -d' ' -f2); \
    IFS=$(echo -en "\n\b"); for LOG in $SORTED_GIT_LOGS; do \
        git show --name-only $LOG; \
    done | less
Nate
  • 93
  • 2
  • 9