views:

286

answers:

3

How to generate changelog of commits groupped by date, in format:

[date today]
- commit message1
- commit message2
- commit message3
...
[date day+3]
- commit message1
- commit message2
- commit message3
...
(skip this day if no commits)

[date day+1]
- commit message1
- commit message2
- commit message3
... 
[date since]
- commit message1
- commit message2
- commit message3

Any git log command, or smart bash script?

A: 

git log has --since and --until, it shouldn't be hard to wrap some stuff around that.

Daenyth
+1  A: 

That would require most certainly some kind of script.
A bit like this commandline-fu

for k in `git branch|perl -pe s/^..//`;do echo -e `git show --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" $k|head -n 1`\\t$k;done|sort -r

(not exactly what you are after but can gives you an idea nonetheless)

I know about GitStats which has also data organized by date (but not the commit messages)


Note: the git branch part of this command is ill-fitted for scripting, as Jakub Narębski comments.
git for-each-ref or git show-ref are natural candidate for scripting commands, being plumbing commands.

VonC
Thanks for this informative answer. One more thing which I need to know: How to list all the commits for the specific, single day: `git log --since="2010-06-02" --until="2010-06-02"` list nothing.
takeshin
@takeshin: did you try `git log --since="2010-06-02" --until="2010-06-03"` ? (from one day - 02 - to another - 03 -)
VonC
@VonC, yeah, but in the simple loop I know only the date, not the next date.
takeshin
@VonC, My plan is: to generate unique list of dates: `git log --pretty="format: %ad" --date=short | uniq` and iterate them in the loop, similar to this from your answer.
takeshin
@takeshin: may be by combining some kind of datetime operation to set the appropriate variables (oneDay, OneDayPlusOne), like in Perl for instance: http://datetime.perl.org/index.cgi?FAQBasicUsage and http://datetime.perl.org/?Modules
VonC
Don't use `git branch` output for scripting; it is user-interface command, and its output can change. Use `git show-ref` or `git for-each-ref` which are intended for scripting.
Jakub Narębski
+1  A: 

Here is dirty, but working version of the script I came up with:

#!/bin/bash
# Generates changelog day by day
NEXT=$(date +%F)
echo "CHANGELOG"
echo ----------------------
git log --no-merges --format="%cd" --date=short | sort -u -r | while read DATE ; do
    echo
    echo [$DATE]
    GIT_PAGER=cat git log --no-merges --format=" * %s" --since=$DATE --until=$NEXT
    NEXT=$DATE
done
takeshin
Just use a pipe into the loop: `produce-and-sort-dates | while read DATE; do …; done`. Incidentally, you might want `GIT_PAGER=cat git log …` for the second one (to prevent *git log* from using a pager when the whole script’s output is going to a terminal). Also, you probably want to be consistent with `--no-merges`, otherwise you might get `[date]` headers without any commits if all the commits for a day were merges.
Chris Johnsen
Thank you Chris. I have updated the code. (Previously I was trying to add the pipe at the end of the loop)
takeshin