git: changelog day by day

老子叫甜甜 提交于 2019-12-29 14:15:09

问题


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?


回答1:


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



回答2:


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



回答3:


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




回答4:


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.




回答5:


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



来源:https://stackoverflow.com/questions/2976665/git-changelog-day-by-day

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!