text Git预提交挂钩(.git / hooks / pre-commit)以防止意外提交调试代码(在源注释中添加NOCOMMIT)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text Git预提交挂钩(.git / hooks / pre-commit)以防止意外提交调试代码(在源注释中添加NOCOMMIT)相关的知识,希望对你有一定的参考价值。

#!/bin/sh

# This pre-commit hook will prevent you from committing any line (or filename) containing
# the string NOCOMMIT. Use that tag in comments around source code you want to avoid
# accidentally committing, like temporary IP addresses or debug printfs.
#
# To add it to an existing repository, save it to .git/hooks/pre-commit (or append, if
# that file already exists). Remember to make executable (chmod +x ...)
#
# To automatically add this pre-commit hook to every repository you create or clone:
#
# mkdir -p "$HOME/.git_template/hooks"
# git config --global init.templatedir "$HOME/.git_template"
# cd "$HOME/.git_template/hooks"
# wget https://gist.githubusercontent.com/hraban/10c7f72ba6ec55247f2d/raw/pre-commit
# chmod +x pre-commit
#

if git diff --cached | grep '^[+d].*NOCOMMIT'; then
    echo
    echo "Adding line containing NOCOMMIT"
    exit 1
fi

以上是关于text Git预提交挂钩(.git / hooks / pre-commit)以防止意外提交调试代码(在源注释中添加NOCOMMIT)的主要内容,如果未能解决你的问题,请参考以下文章

Git 预提交挂钩未在 Windows 上运行

在 Git 中运行预提交挂钩。有没有办法验证脚本是不是正在运行?

git pre receive hook 来检查提交信息

哈士奇预提交挂钩未触发

Git挂钩

Git 预提交挂钩:更改/添加的文件