gpt4 book ai didi

如果字符串出现在源代码(或差异)中,Git 在提交之前发出警告

转载 作者:IT王子 更新时间:2023-10-29 01:10:34 25 4
gpt4 key购买 nike

如果我要提交的更改包含特定字符串(例如,@todo@hack).

有人可以告诉我如何实现吗?

† 或警告。
‡ 或提交时。

最佳答案

检查字符串 '@todo' 是否被添加的简单预提交 Hook 可能如下所示:

#!/bin/sh

. git-sh-setup # for die
if git-diff-index -p -M --cached HEAD -- \
| grep '^+' \
| grep @todo; then
die Blocking commit because string @todo detected in patch
fi

如果这是 .git/hooks/pre-commit 的内容并且是可执行的,任何添加字符串 @todo 的补丁都将被拒绝。

关于如果字符串出现在源代码(或差异)中,Git 在提交之前发出警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7291186/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com