假设我想让我的承诺更加花哨。 每个提交都会有一个特殊的前缀类型,包含在“-”符号中。例如:
-feat- : Added new feature
-fix- : Fixed this annoying bug
-refactor- : Refactored this piece of code
-chore- : Wrote some tests
我想使用 git 别名自动化所有这些前缀。 e.为每种类型创建自定义命令:
comfeat
、comfix
、comref
和 comchore
。
到目前为止,我已经尝试过做这样的事情:
comfeat = "!f() { git add --all && git commit -am '-feat- : ${1}'; }; f"
当我尝试调用这个命令时,我会得到这个:
PS D:\Projects\Test> git comfeat "Added new feature"
[master 9fcb0c9] -feat- : ${1}
附注我对 bash/shell 没有任何先验知识,因此我们将不胜感激任何帮助。
P.S.S.我见过人们使用 git hooks 来提取分支名称并将其添加到提交之前,但我正在独自处理该项目,因此我正在处理的每个功能都没有很多分支。
所以,经过一番挖掘并在 ChatGPT thingie 的帮助下,我实际上找到了这个问题的解决方案。我的 .gitconfig 文件别名部分的最终版本如下所示:
[alias]
comfeat = !sh -c 'git add -A && git commit -m \"-feat- : $1\"' -
comfix = !sh -c 'git add -A && git commit -m \"-fix- : $1\"' -
comchore = !sh -c 'git add -A && git commit -m \"-chore- : $1\"' -
comref = !sh -c 'git add -A && git commit -m \"-refactor- : $1\"' -
现在我可以输入:
git comref "Refactored user class."
我的提交消息如下所示:
[master 0ba3e4c] -refactor- : Refactored user class.