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

author author     2022-12-02     378

关键词:

#!/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

设置预提交挂钩 jshint

】设置预提交挂钩jshint【英文标题】:setuppre-commithookjshint【发布时间】:2013-03-2003:27:19【问题描述】:我最近开了一个projectongithub。我已经设法在每次提交后使用Travis设置自动测试。但现在我也想用jshint设置一个预提交钩子。... 查看详情

预提交挂钩失败

】预提交挂钩失败【英文标题】:PreCommitHookfails【发布时间】:2019-06-0216:38:06【问题描述】:我正在为我的新项目使用NestJs。我正在使用此命令添加所有文件。gitadd.当我在添加所有文件后提交时,husky阻止提交并向我显示此错误... 查看详情

哈士奇预提交挂钩未触发

】哈士奇预提交挂钩未触发【英文标题】:huskypre-commithooknottriggering【发布时间】:2021-10-0422:36:59【问题描述】:我遇到了husky的问题。我希望husky在即将完成gitcommit时运行eslint并且更漂亮,以便它可以强制执行干净的编码检查。... 查看详情

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

】Git预提交挂钩:更改/添加的文件【英文标题】:Gitpre-commithook:changed/addedfiles【发布时间】:2011-01-2515:05:03【问题描述】:我正在编写一个预提交挂钩。我想对所有扩展名为.php的文件运行php-l。但是我被卡住了。我需要获取暂... 查看详情

IntelliJ IDEA 中的预提交挂钩

】IntelliJIDEA中的预提交挂钩【英文标题】:Pre-commithookinIntelliJIDEA【发布时间】:2017-07-2310:34:58【问题描述】:我想在IntelliJIDEA(社区版)中创建一个预提交钩子,用于创建为提交选择的所有文件的列表并将其转储到xml文件中。... 查看详情

预提交/挂钩:没有这样的文件或目录

】预提交/挂钩:没有这样的文件或目录【英文标题】:pre-commit/hook:Nosuchfileordirectory【发布时间】:2017-10-1112:33:27【问题描述】:我在尝试提交时收到此错误。操作系统-最新的OSXGit版本-git版本2.11.0(AppleGit-81).git/hooks/pre-commit:line2:... 查看详情

SVN 的 CPP 检查预提交挂钩

】SVN的CPP检查预提交挂钩【英文标题】:CPPcheckprecommithookforSVN【发布时间】:2017-05-3116:51:05【问题描述】:在开发人员在SVN中提交代码之前,我们需要通过cppcheck自动检查错误和警告,如果代码添加了任何新错误,那么提交应该... 查看详情

如何在预提交挂钩中使用 git diff 的退出代码

】如何在预提交挂钩中使用gitdiff的退出代码【英文标题】:Howtouseexitcodeofgitdiffinpre-commithook【发布时间】:2021-12-0511:15:38【问题描述】:我有一个带有后端和前端的项目,但是由于每次更改都会执行gitpre-commit挂钩,因此我需要... 查看详情

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

】Git预提交挂钩未在Windows上运行【英文标题】:Gitpre-commithookisnotrunningonWindows【发布时间】:2014-01-0318:41:09【问题描述】:我刚刚开始研究Git挂钩,但我似乎无法让它们运行。我设置了一个本地存储库,所以我的项目文件夹中现... 查看详情

Git 预提交挂钩以在文件中查找文本

】Git预提交挂钩以在文件中查找文本【英文标题】:Gitpre-commithooktofindtextinfiles【发布时间】:2015-11-2803:45:39【问题描述】:我正在编写一个gitpre-commit挂钩来检查是否有任何暂存文件包含不允许的文本,如果是这种情况则中止。... 查看详情

将预提交挂钩链接到 VSC 源代码控制

】将预提交挂钩链接到VSC源代码控制【英文标题】:linkingpre-commithooktoVSCsourcecontrol【发布时间】:2021-11-0911:06:40【问题描述】:我的目标是每次我gitcommit时,eslint应该首先运行。目前,我正在使用哈士奇钩子。当我使用gitcommit-m&... 查看详情

颠覆:在预提交挂钩中获取用户的 IP 地址?

】颠覆:在预提交挂钩中获取用户的IP地址?【英文标题】:Subversion:Getip-addressofuserinpre-commithook?【发布时间】:2011-11-2316:54:45【问题描述】:我们正在托管一个用于分布式软件开发的subversion存储库。因此,非员工可以访问我们... 查看详情

VSCODE 和 GitHub 桌面预提交挂钩:npx:找不到命令

】VSCODE和GitHub桌面预提交挂钩:npx:找不到命令【英文标题】:VSCODE&GitHubDesktoppre-commithook:npx:commandnotfound【发布时间】:2021-07-1022:18:03【问题描述】:我正在开始一个新的存储库,我认为我应该使用最新的Huksyv6,它是使用Lint... 查看详情

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

】在Git中运行预提交挂钩。有没有办法验证脚本是不是正在运行?【英文标题】:RunaprecommithookinGit.Isthereawaytoverifythatthescriptisrunning?在Git中运行预提交挂钩。有没有办法验证脚本是否正在运行?【发布时间】:2014-10-0100:29:11【问... 查看详情

如何对 SVN 中的特定文件夹使用预提交挂钩(Windows 批处理文件)?

】如何对SVN中的特定文件夹使用预提交挂钩(Windows批处理文件)?【英文标题】:Howtousepre-commithook(Windowsbatchfile)foraparticularfolderinSVN?【发布时间】:2012-03-0210:51:12【问题描述】:我想在SVN(即Windows的.bat文件)中创建一个预提交... 查看详情

有没有办法让 git commit --verbose 在使用预提交挂钩时显示更新的差异?

】有没有办法让gitcommit--verbose在使用预提交挂钩时显示更新的差异?【英文标题】:Isthereawaytogetgitcommit--verbosetoshowanupdateddiffwhenusingpre-commithooks?【发布时间】:2019-07-0204:05:39【问题描述】:所以我目前正在设置一个gitpre-commit挂... 查看详情

“测试”的 husky 预提交钩子未完成

】“测试”的husky预提交钩子未完成【英文标题】:huskypre-commithookfor\'test\'doesnotfinish【发布时间】:2021-10-2103:52:26【问题描述】:您好,我安装了husky和lint-stage,以便为暂存文件提供lint和tests的预提交挂钩。当我转到gitcommit-m\'so... 查看详情

SVN - 在开始提交挂钩中获取提交大小?

】SVN-在开始提交挂钩中获取提交大小?【英文标题】:SVN-Getcommitsizeinstart-commithook?【发布时间】:2011-09-2209:13:38【问题描述】:实际上,我在预提交挂钩中检查了提交的大小。但是在我可以在pre-commit中拒绝提交之前,所有文件... 查看详情