git: changelog day by day
Asked Answered
M

5

22

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?

Maryannemarybella answered 4/6, 2010 at 18:16 Comment(1)
What if commitdate is non-monotonic, due to clock skew / misconfigured clock for one of contributors?Canned
M
29

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
Maryannemarybella answered 5/6, 2010 at 7:45 Comment(3)
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.Tammietammuz
Thank you Chris. I have updated the code. (Previously I was trying to add the pipe at the end of the loop)Maryannemarybella
@Maryannemarybella great script. However there's an issue with the dates. Specifically, it aggregates today's commits into yesterday. I replaced the GIT_PAGER line with this and it's fixed: GIT_PAGER=cat git log --no-merges --format=" * %s" --since="$DATE 00:00" --until="$DATE 23:59" No need for $NEXT variable after this changeRojo
M
13

I couldn't get the accepted answer to handle today's commits as my setup didn't handle the NEXT variable properly on the first iteration. Git's log parameters will accept a time too, which removes the need for a NEXT date:

#!/bin/bash
# Generates changelog day by day
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 00:00:00" --until="$DATE 24:00:00"
done
Mislead answered 17/1, 2011 at 10:40 Comment(2)
This is really nice. The only thing is that echo [$DATE] doesn't work cause it try to evaluate an expression or whatever. So just remove the brackets and it's fineCapella
the good one. thanksPastern
R
1

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

Radiolarian answered 4/6, 2010 at 18:32 Comment(0)
F
1

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.

Floorboard answered 4/6, 2010 at 18:34 Comment(7)
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.Maryannemarybella
@takeshin: did you try git log --since="2010-06-02" --until="2010-06-03" ? (from one day - 02 - to another - 03 -)Floorboard
@VonC, yeah, but in the simple loop I know only the date, not the next date.Maryannemarybella
@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.Maryannemarybella
@takeshin: may be by combining some kind of datetime operation to set the appropriate variables (oneDay, OneDayPlusOne), like in Perl for instance: datetime.perl.org/index.cgi?FAQBasicUsage and datetime.perl.org/?ModulesFloorboard
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.Canned
Case in point about not using git branch: This breaks when you're in the middle of a rebase.Hemo
T
0

I wrote a script in python to create a week-by-week git log.

You could easily change it to days, months, etc by changing the timedelta

https://gist.github.com/NahimNasser/4772132

Tuckerbag answered 12/2, 2013 at 18:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.