{"id":26923868,"url":"https://github.com/lei4519/inspect-commits","last_synced_at":"2026-05-01T15:31:21.012Z","repository":{"id":37423676,"uuid":"438939294","full_name":"lei4519/inspect-commits","owner":"lei4519","description":"检查 Git Commits 中的敏感词","archived":false,"fork":false,"pushed_at":"2022-06-21T09:38:08.000Z","size":2435,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-02T01:52:33.995Z","etag":null,"topics":["git","git-hooks","pre-push"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lei4519.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-16T09:54:04.000Z","updated_at":"2022-05-16T14:07:46.000Z","dependencies_parsed_at":"2022-08-18T23:23:09.151Z","dependency_job_id":null,"html_url":"https://github.com/lei4519/inspect-commits","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/lei4519/inspect-commits","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lei4519%2Finspect-commits","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lei4519%2Finspect-commits/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lei4519%2Finspect-commits/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lei4519%2Finspect-commits/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lei4519","download_url":"https://codeload.github.com/lei4519/inspect-commits/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lei4519%2Finspect-commits/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32502927,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"online","status_checked_at":"2026-05-01T02:00:05.856Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["git","git-hooks","pre-push"],"created_at":"2025-04-02T01:52:36.279Z","updated_at":"2026-05-01T15:31:20.995Z","avatar_url":"https://github.com/lei4519.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Inspect Commits\n\n检查 Git Commits 中的敏感词\n\n\u003e 不支持 windows 系统\n\n![](https://raw.githubusercontent.com/lei4519/picture-bed/main/images6B1F78A6-4351-432D-AD8A-A7C47AC5BF36.png)\n\n## 安装\n\n```sh\n/bin/bash -c \"$(curl -fsSL https://raw.githubusercontent.com/lei4519/inspect-commits/master/scripts/install)\"\n```\n\n安装成功后，在终端中执行 `inspect-commits` 命令应该会有信息输出。\n```sh\ninspect-commits\n```\n\n## 卸载\n\n```sh\n/bin/bash -c \"$(curl -fsSL https://raw.githubusercontent.com/lei4519/inspect-commits/master/scripts/uninstall)\"\n```\n\n## 命令\n\n```sh\nSUBCOMMANDS:\n    check                检查当前分支中未提交到远程仓库的 commits\n    checkall             检查当前分支下的所有 commits\n    config               编辑配置文件；-p 参数返回文件地址\n    set-global-hook      将程序配置为 git global core.hooksPath\n    unset-global-hook    清除 git global core.hooksPath 配置\n```\n\n### `inspect-commits config`\n编辑配置文件，文件格式为 JSON。\n\n#### Config 格式\n```ts\n// 可配多个规则\ntype Rules = Array\u003cRule\u003e\n\ntype Rule = {\n\t// 当前规则需要排除的远程地址\n\texclude_repo_urls: Array\u003cstring\u003e\n\t// 当前规则需要检查的敏感词\n\twords: Array\u003cstring\u003e\n}\n```\n\n#### 配置示例\n```json\n{\n  \"rules\": [\n    {\n      \"exclude_repo_urls\": [\n        \"github.com\"\n      ],\n      \"words\": [\n        \"password\"\n      ]\n    },\n    {\n      \"exclude_repo_urls\": [\n        \"gitlab.com\"\n      ],\n      \"words\": [\n        \"sensitive\"\n      ]\n    }\n  ]\n}\n```\n\n### `inspect-commits check`\n检查当前分支中未提交到远程仓库的 commits\n\n```sh\ninspect-commits check origin\n```\n\n### `inspect-commits checkall`\n检查当前分支下的所有 commits\n\n### `inspect-commits set-global-hook`\n将程序配置为全局的 pre-push hook，实际就是在设置 `git config --global core.hooksPath`\n\n### `inspect-commits unset-global-hook`\n清除全局 hook 配置，等同于执行 `git config --global --unset core.hooksPath`。\n\n⚠️ 注意：\n- 如果已存在全局 hook，此命令显示警告信息，并覆盖已存在的 hook。\n- 如果在 git 仓库中配置了 hooksPath 会覆盖 git 全局的 hook\n\n如果存在以上情况，可以使用 [husky](https://github.com/typicode/husky) 进行多 hook 管理。\n\n## 配合 Husyk\n\n安装 Husky 并生成 `.husky/pre-push` 脚本后，将以下内容放入脚本中\n\n```sh\nread local_ref local_sha remote_ref remote_sha\ninspect-commits check $1 $remote_ref  $local_ref\n```\n\n\n## 为什么不是 pre-commit?\n\n- pre-commit 可以被 `--no-verify` 跳过，pre-push 无法被跳过\n- commit 会很频繁，而 push 不会\n- 敏感信息暴露出去才算风险，在电脑中不算\n\n## 检测出 commit 包含敏感信息，如何修复？\n\n使用 `git rebase -i`, 对目标 commit 进行 `edit`，详情参考 [Git 工具 - 重写历史](https://git-scm.com/book/zh/v2/Git-%E5%B7%A5%E5%85%B7-%E9%87%8D%E5%86%99%E5%8E%86%E5%8F%B2)\n\n⚠️  如果包含敏感信息的 commit 已经提交到了远程仓库，重写 commit 后强制推送也没有用。只要 commit 到了远程仓库就会被永久记录，唯一的办法就是删除并重建远程仓库。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flei4519%2Finspect-commits","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flei4519%2Finspect-commits","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flei4519%2Finspect-commits/lists"}