【发布时间】:2020-06-04 08:39:10
【问题描述】:
是否可以编写一个 git 钩子在第一次提交之前设置用户名和电子邮件?用户名和电子邮件应根据配置的参数(如存储库/域正则表达式或其他参数)进行设置。
我尝试编写不同的类型,但我只成功了配置更改在第一次提交之后。
编辑
我的代码如下所示(基于Create a global git commit hook):
.git-templates/hooks/ -> cat pre-commit
#!/bin/bash
remote=$(git config --get remote.origin.url)
if [ -n "$remote" ]; then
if [[ $remote =~ "specific_domain" ]]; then
git config user.email "myname@specific_domain.tld"
git config user.name "Firstname Lastname"
else
git config user.email "pseudonym@general_domain.tld"
git config user.name "pseudonym"
fi
fi
【问题讨论】:
-
你试过哪些钩子?你能分享一些你的代码吗?你试过
pre-commit吗? -
@shreyasminocha 添加了我的代码