tags:

views:

771

answers:

6

Or just all the commits that occurred between two dates? In SVN, you could do something like svn diff -r{date}:{date} to do it! I can't seem to find a git equivalent to this.

Specifically I'm looking at writing a script to send out daily emails with all the code committed that day and by who.

+6  A: 

You could use git whatchanged --since="1 day ago" -p

It also takes a --until argument.

Docs

seth
thanks! This was right what I wanted, it even takes the --committer parameter, though thats not listed in its documentation! also, 'git whatchanged' didn't appear in 'git help'! No idea why... thanks again.
brbob
You should make this your chosen answer so seth gets some karma.
Scott
@Scott thanks for watching my back!
seth
This should be marked as the accepted answer. :)
Tim Visher
Man what a kick in the nuts for seth
dasil003
A: 
gahooa
+4  A: 

"date" is a bit of a loose concept in git. A commit will have an author date that may be some time well in the past before someone actually pulls/commits the commit into their repository, also the commit may be rebased and updated to be on top of an apparently newer commit.

A commit also has an commit date which is updated if a commit is rebased or amended in any way. These commits are more likely to be in some sort of chronological order but you are still at the mercy of the committer having the correct time set on his computer and even so, an unmodified commit can sit on a feature branch on a remote repository indefinitely before being merged into the master branch of a central repository.

What is probably most useful for your purposes is the reflog date on the particular repository in question. If you have per-branch reflogs enabled (see git config core.logAllRefUpdates) then you can use the ref@{date} syntax to refer to where a branch was at a particular time.

E.g.

git log -p master@{2009-07-01}..master@{now}

You can also use 'fuzzy' descriptions like:

git log -p "master@{1 month ago}..master@{yesterday}"

These commands will show all commits that have 'appeared' in the given branch of the repository regardless of how 'old' they actually are according to their author and commit dates.

Note that the per-branch reflog is specific to a repository, so if you're running the log command on a clone, and you don't pull for (say) a month then pull all the changes for the last month at once, then all of the last month's changes will appear in a @{1 hour ago}..@{now} range. If you are able to run the log command on the 'central' repostory that people push to, then it may do what you want.

Charles Bailey
Very good writeup and good answer to stated question... but I think it wouldn't help much with doing what brbob intended.
Jakub Narębski
It depends, it might help if he actually wants to parse what was pushed to a certain branch on a certain central repository and the log command was run on that repository. I think that an edit is in order...
Charles Bailey
"commit date which is updated if a commit is rebased or amended in any way", actually the date is never changed; the whole commit gets replaced with another commit (although the tree could supposedly be the same).
hasen j
@hasen j: Technically, you're correct. Commits are immutable. When you rebase or amend a commit and create a new commit, the existing commit message, author details and author date are often copied from the old commit so it's _like_ you're updating the commit with a new commit id and commit date.
Charles Bailey
A: 

You can also use git-format-patch to prepare patches (diffs) and send them through email.

Use options [since] or [revision range] to specify commits range.

Nick D
+1  A: 

Perhaps

$ git format-patch --committer=<who> --since=yesterday --stdout

is what you want (with or without '--stdout')?

Jakub Narębski
Quick question, does --since use the commit date?
Charles Bailey
+2  A: 

The previous suggestions have some drawbacks. Basically, I was looking for something equivalent to cvs diff -D"1 day ago" -D"2010-02-29 11:11". While collecting more and more information, I found a solution.

Things I have tried:

  • git whatchanged --since="1 day ago" -p from here

    But this gives a diff for each commit, even if there are multiple commits in one file. I know that "date" is a bit of a loose concept in git, I thought there must be some way to do this.

  • git diff 'master@{1 day ago}..master gives some warning warning: Log for 'master' only goes back to Tue, 16 Mar 2010 14:17:32 +0100. and does not show all diffs.

  • git format-patch --since=yesterday --stdout does not give anything for me.

  • revs=$(git log --pretty="format:%H" --since="1 day ago");git diff $(echo "$revs"|tail -n1) $(echo "$revs"|head -n1) works somehow, but seems complicated and does not restrict to the current branch.

Finally:

Funnily, git-cvsserver does not support "cvs diff -D" (without that it is documented somewhere).

Weidenrinde