gpt4 book ai didi

git - 如何进行git预提交代码检查?

转载 作者:太空狗 更新时间:2023-10-29 14:46:00 27 4
gpt4 key购买 nike

第一个问题...是否有可能用 git 来完成? :)

我想要的是:

有时,出于我自己的调试目的,我会将代码中的一个变量切换为 true (localMode = true;)。但这永远不应该被提交。我应该只提交变量设置为 false 的代码。当然,有时我会忘记进行此更改。如果我要提交“错误的”代码,git 是否有可能以某种方式停止或警告我?

更新:
感谢您的帮助!我最终得到了以下 shell 脚本:

#!/bin/bash
git diff --cached --name-only | while read FILE; do
if [[ $(echo "$FILE" | grep -E "^.+main\-controller\.js$") ]]; then
content=$(<"$FILE")
if [[ $(echo "$content" | grep -E "rootScope\.localMode = true") ]]; then
echo -e "\e[1;31m\tCommit contains localMode set to true.\e[0m" >&2
exit 1
fi
fi
done

最佳答案

下面的链接呢?

http://wadmiraal.net/lore/2014/07/14/how-git-hooks-made-me-a-better-and-more-lovable-developer/

我认为您可以在链接的示例代码中添加一些正则表达式来检测 localMode = true

关于git - 如何进行git预提交代码检查?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26992576/

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