253

I've already looked at the relevant docs from git-scm.com and gitref.org, but I can't seem to figure this out.

Let's say I want to get all commits for Tuesday, November 12th, 2013. Using an existing repo as an example, I know for a fact that I have commits on that day, as well as commits the day before and the day after.

With 2013-11-11 and 2013-11-12

All the following give me commits for both November 11th and 12th:

  • git log --after="2013-11-11" --until="2013-11-12"
  • git log --since="2013-11-11" --until="2013-11-12"
  • git log --after="2013-11-11" --before="2013-11-12"
  • git log --since="2013-11-11" --before="2013-11-12"

With 2013-11-12 only

All the following give me no commits:

  • git log --since="2013-11-12" --until="2013-11-12"
  • git log --since="2013-11-12" --before="2013-11-12"
  • git log --after="2013-11-12" --until="2013-11-12"
  • git log --after="2013-11-12" --before="2013-11-12"

With 2013-11-12 and 2013-11-13

As expected (from the results of 2013-11-11 and 2013-11-12 above), all of the following give me results from both November 12th and 13th:

  • git log --since="2013-11-12" --before="2013-11-13"
  • git log --after="2013-11-12" --before="2013-11-13"
  • git log --since="2013-11-12" --until="2013-11-13"
  • git log --after="2013-11-12" --before="2013-11-13"

...and so on and so forth. I feel like I've tried every possible combination of since, after, before, and until but still can't find the answer, nor do I understand whether those options are inclusive or exclusive, since they seem to be inclusive if the two dates are different, but exclusive if they're on the same day. Did I miss something / what am I doing wrong?!

BartoszKP
  • 34,786
  • 15
  • 102
  • 130
3cheesewheel
  • 9,133
  • 9
  • 39
  • 59
  • 11
    I've found git's since/after/until/before handling very weird myself, so I don't know the answer, but have you tried specifying date+time (e.g., --since="2013-11-12 00:00")? Also, do (any of) your commits have different committer vs. author dates? – John Bartholomew Nov 14 '13 at 20:05
  • You got it! Specifying the time worked. It didn't even occur to me to try it with a time. Thanks! As for committer vs. author dates -- there were no patches applied during those dates, so that wasn't it. – 3cheesewheel Nov 14 '13 at 20:08
  • Seems to me that 'git log --boundary' should do this for you, so that 'git log --boundary --after="2013-11-12" --before="2013-11-12"' would show exactly one commit (the one you think it would :) ). – qneill Sep 26 '16 at 17:54

5 Answers5

334

Thanks John Bartholomew!

The answer is to specify the time, e.g. git log --after="2013-11-12 00:00" --before="2013-11-12 23:59"

Stevoisiak
  • 23,794
  • 27
  • 122
  • 225
3cheesewheel
  • 9,133
  • 9
  • 39
  • 59
  • 16
    Nice. However, that command will omit commits between 23:59 and 00:00 the next day, therefore `git log --after="2013-11-12 00:00" --before="2013-11-13 00:00"` is better. I believe `gitk --since="2013-11-12 00:00" --until="2013-11-13 00:00" &` would also work if you have gitk installed. – HelloGoodbye Mar 04 '16 at 12:50
  • 7
    In git 2.13.0. `git log --after="2017-07-25" --before="2017-07-26"` gives valid results for me. – powlo Jul 27 '17 at 09:08
  • 3
    Is this for the current checked out branch? How to see across all branches? – nawfal Oct 30 '19 at 06:17
  • This is the correct answer, but I'm still baffled by it and posted this follow-up question: https://stackoverflow.com/questions/59691065/what-does-git-log-since-until-do-when-there-is-no-hhmmss-supplied-in-the-v – bgoodr Jan 11 '20 at 02:07
  • Would be great if I count get the count too – Ed_ May 27 '21 at 15:16
47

I usually check my git log and see what I was working on a specific day and update my timesheet based on that, but it's a pain in the ass to type in the full date in ISO format so I just do it like this

git log --after=jun9 --before=jun10

and I add --author to only print my commits

git log --since=jun9 --until=jun10 --author=Robert 

This prints commits that happened on the last 9th of June (so for 2016 in this case and not for 2015 or 2014 and so on).

The --since/--after and --until/--before parameters can also take stuff like 3 days ago, yesterday, etc.

Kohányi Róbert
  • 9,791
  • 4
  • 52
  • 81
  • Simply doesn't work, outputs nothing. Am I missing anything? Should I specify a branch? – Aurimas Mar 14 '17 at 18:35
  • 1
    @Aurimas Well, not sure what went wrong on your end. If your `since` and `until` values aren't correct you'll get no output that's for sure. Use `git log` first, and try to pick a `since` and `until` value based on what you see. No branch or anything special required. Not sure since which Git version this feature is available. Make sure you have a recent version as well. – Kohányi Róbert Mar 15 '17 at 15:58
  • 10
    I had to use spaces: `git log --after="may 2" --before="may 3"` – Connor Clark Jun 01 '18 at 21:00
23

Nothing wrong with the accepted answer (which I upvoted), but... we're here for science!

The output below can be expanded/customised with pretty=format:<string> placeholders:

git log --pretty='format:%H %an %ae %ai' | grep 2013-11-12

Not 100% immune to errors as the same string could have been entered by a user. But acceptable depending on which placeholders are used. The snippet above would not fail, for instance.

One could as well just parse the whole git log to JSON and consume/manipulate its data to one's heart content. Check https://github.com/dreamyguy/gitlogg out and never look back!

Disclaimer: that's one of my projects.

Wallace Sidhrée
  • 11,221
  • 6
  • 47
  • 58
19

I made a git alias for that specific purpose:

commitsAtDate = "!f() { git log --pretty='format:%C(yellow)%h %G? %ad%Cred%d %Creset%s%C(cyan) [%cn]' --decorate --after=\"$1 0:00\" --before=\"$1 23:59\" --author \"`git config user.name`\"; }; f"

Usage:

git commitsAtDate 2017-08-18

It results in a nicely scannable output:

screenshot of four commits at a specific date by the author

Michael Große
  • 1,818
  • 1
  • 16
  • 20
  • 4
    you also can specify relative dates to this alias, i.e. `git commitsAtDate yesterday`, `2 days ago`, etc. – voiger Mar 01 '19 at 08:22
  • You can also omit the date entirely to get today's commits, e.g. `git commitsAtDate`. Neat! – Mr_Chimp May 17 '23 at 14:07
-2

This script displays the available date range of commits for the current repo, then prompts for the date that you want to see commits from. It displays a short SHA and the full SHA, the author, the commit timestamp, and the comments in single quotes.

The script keeps prompting for dates until you press Enter or Control-D.

Mac users: requires gnu date.

#!/bin/bash

COMMITS=`git log --abbrev-commit --pretty="format:%h %H %ai" | sort -k3 -k4`
FIRST=`echo "$COMMITS" | head -n 1`
LAST=`echo "$COMMITS" | tail -n 1`
echo "First commit: $FIRST"
echo "Last commit: $LAST"
printf "Date to search for commits: "
read DATE
while [[ "$DATE" ]]; do
  NEXT_DATE=`date +%Y-%m-%d -d "$DATE +1 day"`
  #echo "Searching for commits from $DATE to $NEXT_DATE"
  echo `git log --after="$DATE" --before="$NEXT_DATE" --pretty="format:%h %H %an %ci '%s'"`
  printf "\nDate to search for commits: "
  read DATE
done

I called the script commitsOnDates, and here it is in action. The first date I enter has no commits, so the response is just an empty line:

$ commitsOnDates
First commit: 375bcfb 375bcfbbf548134a4e34c36e3f28d87c53b2445f 2015-08-03 13:37:16 -0700
Last commit: 1d4c88c 1d4c88ce6a15efaceda1d653eed3346fcae8f5e6 2018-10-13 21:32:27 -0700
Date to search for commits: 2015-08-13


Date to search for commits: 2015-08-03
375bcfb 375bcfbbf548134a4e34c36e3f28d87c53b2445f Mike Slinn 2015-08-03 13:37:16 -0700 'this is a comment'

Date to search for commits: 2018-10-13
1d4c88c 1d4c88ce6a15efaceda1d653eed3346fcae8f5e6 Mike Slinn 2018-10-13 21:32:27 -0700 'a comment' 64d6e16 64d6e16338657b82c91ac94bea8ebf7b80dc4c28 Mike Slinn 2018-10-13 18:28:41 -0700 'nother comment' d5eb26e d5eb26e49fc9dceee9b9f5a2d8fa052bff2cfbbc Mike Slinn 2018-10-13 18:16:20 -0700 'no comment' d8a4992 d8a4992df208ba5efb50728311820bdad5ba5332 Mike Slinn 2018-10-13 12:02:00 -0700 'commented'

Date to search for commits:
Mike Slinn
  • 7,705
  • 5
  • 51
  • 85