本地项目git hooks配置记录

1.commit格式检查hook【mac环境,可重命名项目根目录/.git/hooks/commit_msg.sample为commit_msg,然后用下方内容覆盖即可】【可通过下方git约束模版检查的commit示例:fix(app): fix xxxxx】:

# This example catches duplicate Signed-off-by lines.

message_file = ARGV[0]
message  = File.read(message_file)

$regex = /(^feat|^fix|^docs|^style|^refactor|^test|^chore)\(.*\)\:\s.*/

if !$regex.match(message)
   puts "
\n[Policy] Your message is not formatted correctly
\nSamples:
\nfeat(modulename): what you did.
\nfix(modulename): what you did.
\ndocs(modulename): what you did.
\nstyle(modulename): what you did.
\nrefactor(modulename): what you did.
\ntest(modulename): what you did.
\nchore(modulename): what you did.
\nSee rules https://www.bing.com"
   exit 1
end

2.如果需要配置全局git hooks,可按如下配置:

1.创建/usr/local/.git_template/.git_template目录
2.将第一步中创建的commit_msg文件拷贝至上方目录
3.git config --global init.templatedit /usr/local/.git_template/.git_template使用该命令将git全局配置模版重定向到第一步中创建到目录
4.如上三步完成后即可在创建新的使用git管理的项目的时候自动将全局模版拷贝至项目根目录/.git/目录下,如果完成如上三步后需要对已经存在对git项目使用该模版,可移动至目标项目根目录并执行git init即可

 

你可能感兴趣的:(原创)