【发布时间】:2017-09-30 13:54:42
【问题描述】:
我正在尝试为默认提交消息添加别名,如下所示:
alias gc='git commit -m "Default commit: $(date)"'
但我不喜欢日期的默认格式并想将其更改为:
date +'%A, %d %B %Y %H:%M:%S' # Tuesday, 02 May 2017 23:12:07
我遇到了如何在别名中构建它的问题。我无法处理多个双引号和单引号。有人可以帮忙吗?
编辑。
感谢关于使用函数和代码的建议。基于此,我做了这个,略有改动:
gc ()
{
if [ "$#" == "0" ]; then
itsmsg="Deafult commit";
else
itsmsg="$*";
fi;
git commit -m "$itsmsg ($(date +'%A, %d %B %Y %H:%M:%S'))"
}
【问题讨论】:
-
改用函数。