如何使commitizen覆盖默认的git commit命令 [英] how to make commitizen override default git commit command

查看:94
本文介绍了如何使commitizen覆盖默认的git commit命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在通过执行 npm run commit 创建自定义脚本来运行commitizen commit命令,但是我想让它随同npm run commit 以某种方式.....因此,任何执行 git commit 的人都会自动将人员引导到commitizen接口,并忽略该人员在 git commit 之后放置的内容.当commitizen可用时.

I am currently creating custom script to run commitizen commit command by doing npm run commit but I want to just let it over ride the default git commit with npm run commit somehow..... So anyone does git commit will automatically direct the person to the commitizen interface and ignore whatever the person put after git commit when commitizen is available.

我该怎么做?我做了google,找不到可行的解决方案.

How can I do that? I did google, can't find a viable solution.

谢谢

推荐答案

不可能通过git本身覆盖默认的git命令,但是您可以将以下内容放在您的 .bashrc 中:

It is impossible to override the default git command through git itself, but you can put the following in your .bashrc:

function git() {
    case $* in
        commit* ) npm run commit ;; # or yarn commit
        * ) command git "$@" ;;
    esac
}

如果第二个参数是"commit",它将覆盖git命令,否则,将使用普通的git命令.( command 确保我们不会递归使用函数-它会直接转到git可执行文件,而不是返回到我们定义的函数.)

This will override the git command if the second argument is "commit", and use the normal git command if not. (The command ensures that we do not use our function recursively - it will go directly to the git executable, not back to our defined function.)

请参见此处此答案更多信息.

请注意 commitizen docs 中的警告:

Note the warning in the commitizen docs:

注意:如果由于使用了诸如husky之类的东西而使用了precommit钩子,则需要为脚本命名而不是"commit"(例如,"cm":"git-cz").原因是因为npm-scripts具有功能",它会自动运行名称为prexxx的脚本,其中xxx是另一个脚本的名称.本质上,如果您将脚本命名为"commit",则npm和husky将运行两次"precommit"脚本,并且解决方法是防止npm触发的precommit脚本.

NOTE: if you are using precommit hooks thanks to something like husky, you will need to name your script some thing other than "commit" (e.g. "cm": "git-cz"). The reason is because npm-scripts has a "feature" where it automatically runs scripts with the name prexxx where xxx is the name of another script. In essence, npm and husky will run "precommit" scripts twice if you name the script "commit," and the work around is to prevent the npm-triggered precommit script.

我建议改用 yarn cz / npm run cz .

这篇关于如何使commitizen覆盖默认的git commit命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆