bash git:日复一日的更新日志
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2976665/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git: changelog day by day
提问by takeshin
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?
任何 git log 命令或智能 bash 脚本?
回答by takeshin
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
回答by kristianlm
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:
我无法得到可接受的答案来处理今天的提交,因为我的设置在第一次迭代时没有正确处理 NEXT 变量。Git 的日志参数也将接受一个时间,这消除了对 NEXT 日期的需要:
#!/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
回答by Daenyth
git loghas --sinceand --until, it shouldn't be hard to wrap some stuff around that.
git loghas --sinceand --until,围绕它包装一些东西应该不难。
回答by VonC
That would require most certainly some kind of script.
A bit like this commandline-fu
那肯定需要某种脚本。
有点像这个命令行-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 exactlywhat you are after but can gives you an idea nonetheless)
(不完全是你想要的,但可以给你一个想法)
I know about GitStatswhich has also data organized by date (but not the commit messages)
我知道GitStats也有按日期组织的数据(但不是提交消息)
Note: the git branchpart of this command is ill-fitted for scripting, as Jakub Nar?bskicomments.git for-each-refor git show-refare natural candidate for scripting commands, being plumbingcommands.
注意:git branch正如Jakub Nar?bski评论的那样,此命令的一部分不适合编写脚本。git for-each-ref或者git show-ref是脚本命令的自然候选者,即管道命令。
回答by Nahim Nasser
I wrote a script in python to create a week-by-week git log.
我用 python 编写了一个脚本来创建每周一次的 git 日志。
You could easily change it to days, months, etc by changing the timedelta
您可以通过更改 timedelta 轻松将其更改为天、月等

