[英]Is it possible to save a git commit message to a file in a pre-commit hook?
I am looking for a way to create a log of commit messages with timestamps for each of my commit messages as a way to keep track of what I've done for the week? 我正在寻找一种方法来创建一个提交消息日志,其中包含每个提交消息的时间戳,以此来跟踪我本周所做的事情? Does anyone have an example of this?
有没有人有这样的例子?
You can create a commit.sh bash script to simplify the process. 您可以创建commit.sh bash脚本来简化该过程。
#!/bin/bash
## your timestamp
NOW=$(date +%Y.%m.%d-%H:%M:%S)
## your source file
g=main.sh
## get the current version by extracting from the first 3 lines
## ideally they are comments, containing the version
cv=`head -n 3 $g | grep "version" | sed 's/[^0-9.]*//g'`
## if you want a new version automatically incremented
nv=`echo $cv | awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{if(length($NF+1)>length($NF))$(NF-1)++; $NF=sprintf("%0*d", length($NF), ($NF+1)%(10^length($NF))); print}'`
## automatically apply it in your sourcecode
echo "Updateing $g from $cv to $nv $NOW"
## re-print the first 3 lines of your code - this is bash here
cat $g > $g.bak
echo '#!/bin/bash' > $g
echo '# Last update:'$NOW >> $g
echo '# version '$nv >> $g
tail -n +4 $g.bak >> $g
rm $g.bak
## git action
git add . --all
git commit -m "$nv $1"
git push
## If you want a log of your commits
echo "$NOW - Updated $g from $cv to $nv - $1" >> $0.log
So you can: 所以你可以:
./commit.sh "I worked a lot on this, now it's done."
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.