27

How to get diff for specified user between two dates from git? Or, how to use git whatchanged command to list commits for specified user?

Is there any none-scripting way (builtin git command)?

Amit Joshi
  • 15,448
  • 21
  • 77
  • 141
Mixter
  • 271
  • 3
  • 3

3 Answers3

36

I believe there's no such a way to get a diff only knowing dates.

As of today you can do the following:

git log --since "OCT 4 2011" --until "OCT 11 2011" --pretty=format:"%H"

And then git diff between first and last revisions. If the revision list is far too long, use the above git log ... with | head -1 and | tail -1 to get the first and the last revisions.

Note that the above git log will return revisions exactly between given dates, i.e. revisions for OCT 5, OCT 6, ..., OCT 10.

oldhomemovie
  • 14,621
  • 13
  • 64
  • 99
  • You can _sort_ of do it directly with diff, but not so reliably, using the `@{date}` notation, e.g., `git diff @{date1} @{date2}`. The problem with that is that the `@{date}` construct doesn't look at the commit history to translate the date into a commit-id, but instead uses the _revlog_. The result is that if you pull _really often_, your revlog will have fine-grained enough info that the above may do what you want, but if you _don't_, the results will be inaccurate... – snogglethorpe Oct 28 '11 at 09:01
  • I had to add equal sign to make it work: ```git log --since="FEB 1 2014" --until="FEB 30 2014"``` – bonyiii May 16 '14 at 14:46
4

This is possible, and with the user / committer criteria:

git log --after="2015-10-14" --before="2015-10-21" --grep="MB[FT][0-9-]*" --author="John\|Mary"

This will match anything

  • between those date
  • by authors matching the names John or Mary
  • where the commit message includes (e.g. a Jira ticket number in the form of) MBT or MBF plus a number-code that can include a - char.
New Alexandria
  • 6,951
  • 4
  • 57
  • 77
0
git log --since "MAY 1 2017" --until "MAY 31 2017" -p --author="Jack" > diffJackMay.patch
andrew
  • 3,083
  • 4
  • 24
  • 29