【发布时间】:2012-03-09 00:26:09
【问题描述】:
我的计划是使用 git 来跟踪 /etc 中的更改,但是在提交时,我希望通过在命令行上添加 --author 选项让进行更改的人将自己指定为作者。
所以我想以 root 身份停止意外提交。
我尝试创建这个预提交挂钩,但它不起作用 - 即使我在提交行指定作者,git var 仍然返回 root。
AUTHOR=`git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/\1/p'`
if [ "$AUTHOR" == "root <root@localhost>" ];
then
echo "Please commit under your own user name instead of \"$AUTHOR\":"
echo 'git commit --author="Adrian"'
echo "or if your name is not already in logs use full ident"
echo 'git commit --author="Adrian Cornish <a@localhost>"'
exit 1
fi
exit 0
【问题讨论】:
-
令人惊讶的是,似乎没有办法获取这些信息。我可以确认
git var GIT_AUTHOR_IDENT显示的是原作者,而不是通过--author提供的作者...
标签: git hook pre-commit