所以我有一个 sh 脚本,它将一些文件放在一起,然后将它们提交到 git repo。如何将日期动态添加到我的提交消息中?
我的 .sh 看起来像
// do things to files...
git add -u;
git commit -m 'generated files on <date here?>';
git push origin master;
只需格式化date命令的输出,Bob 就是你的叔叔:
// do things to files...
git add -u;
git commit -m "generated files on `date +'%Y-%m-%d %H:%M:%S'`";
git push origin master
为什么不使用prepare-commit-msg
或commit-msg
git hooks?您可以在.git/hooks
目录中找到存根。
不知道为什么要这样做,因为提交已经加上时间戳,但类似于:
THEDATE=`date`
git commit -m "... $THEDATE"
会这样做。请注意,双引号很重要。