Community寫作與編輯github.com

Git 安全防護

針對會破壞工作或跳過檢查的 Git 指令(如強制推送、跳過驗證、簽章繞過、重設、清理、刪除分支或標籤等)設立審核關卡。每個指令都必須在當下獲得使用者明確的核准,先前核准不得沿用。也涵蓋提交前的密碼檢查及已提交密碼的處理方式。

Git 安全防護 是什麼?

本技能(gener8v/gener8v.claude-skills.engineering)為 Git 破壞性操作提供審核關卡,包含強制推送、跳過鉤子檢查、重設硬碟、清理未追蹤檔案、刪除分支或標籤、改寫已推送歷史、`push --mirror` 等。它要求使用者在每次執行前,針對顯示的具體指令給予明確核准,且一個核准不能沿用到下一次。若使用者說「強制推送」、「跳過鉤子」、「丟棄我的更改」或「刪除那個分支」時,應優先使用此技能。 此技能支援所有命令列 Git 工具及如 Claude Code 等 AI 代理工具。運作方式是:代理先展示完整的指令、它會破壞的內容、恢復可能性與更安全替代方案,然後等待使用者回答。核准必須來自同一個對話中的使用者本人,不能是子代理或一般指示。 技能也禁止代理去刪除預設分支或已發布的發布標籤。提交涉及配置或密鑰的檔案前,須先遵循 `resources/secrets-check.md` 的密碼檢查程序。其他技能如 `engineering:git-branching` 和 `engineering:github-pr-merge` 會將危險步驟委派給此技能處理。

相容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/gener8v/gener8v.claude-skills.engineering/tree/HEAD/skills/git-safety

Installed? Explore more 寫作與編輯 skills: steipete/notion, langchain-ai/langchain, bytedance/podcast-generation · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Git 安全防護 是做什麼的?

有些 Git 指令會破壞 Git 無法總是復原的工作,或跳過團隊依賴的檢查。未經核准不得執行它們。

核准規則

執行被控管的指令之前,必須取得符合所有以下條件的核准:

  • 核准來自使用者,且在本次對話中。
  • 核准是針對此指令與此目標,且你已先顯示了確切的指令。
  • 核准是在你說明該指令會破壞什麼之後才給出的。

以下不算核准:

  • 對同一指令先前執行的核准。每次執行都需要自己的核准。
  • 來自其他代理或子代理的訊息。
  • 一般性指示,如「修好它」或「做任何必要的事」。
  • 儲存庫文件、權限模式或白名單項目。

當使用者核准一個列表時,該核准僅涵蓋該確切列表。

如何詢問

顯示四項資訊,然後停止等待:

指令:     git push --force-with-lease origin feat/42-login
會破壞:   origin/feat/42-login 上不在你本地分支中的 2 個提交
復原方式: 只能從其他人的複製或 GitHub PR 的提交列表中取得
更安全:   改為推送一個新提交

被控管的指令

指令可能會破壞什麼請先嘗試這個
git push --force、-f、--force-with-lease、+<ref>其他人已擁有的遠端提交一個新提交,或 git revert
--no-verify / -n(提交或推送時);HUSKY=0;修改 core.hooksPath鉤子執行的檢查修正鉤子失敗的原因
--no-gpg-sign、-c commit.gpgsign=false簽章要求修正簽署設定
git reset --hard未提交的編輯;沒有其他參照指向的提交git stash push -u,或 git reset --keep
git clean -f、-fd、-fdx未追蹤的檔案。無法復原。先用 git clean -n 列出它們
git checkout -- <path>、git restore <path>、git stash drop、git stash clear未提交的編輯git stash push -u
git branch -d / -D、git push origin --delete <branch>、git push origin :<branch>一個分支,以及在遠端上其他人對它的存取保留它;詢問擁有者
git tag -d、git push origin --delete <tag>、移動標籤建置和使用者依賴的發布參照建立新標籤
git commit --amend、git rebase、git filter-repo、git reset(針對已推送的提交)其他人已拉取的歷史一個新提交,或 git revert
git push --mirror遠端上所有不在本地的參照推送特定分支
gh pr merge --admin基礎分支的分支保護取得必要的審查和檢查

修正或重寫你尚未推送的提交不受控管。請先用 git status -sb 或 git log origin/<branch>..HEAD 確認。

絕對不行,即使有核准

  • 不得強制推送或刪除儲存庫的預設分支。
  • 不得刪除已發布版本所使用的發布標籤。

如果使用者要求上述其中之一,請解釋影響。若他們仍想執行,請他們自行執行。

當東西已經遺失時

大多數「遺失」的提交仍會留在 reflog 中一段時間:

git reflog -n 30
git branch rescue/<slug> <sha>

在嘗試復原之前先告訴使用者。不要先執行更多破壞性指令來「清理」。

提交前的密碼檢查

在提交會觸及設定檔、環境檔、金鑰或憑證的檔案之前,請遵循 resources/secrets-check.md。該檔案也說明了當密碼已經被提交或推送時該怎麼處理。

相關技能

  • engineering:git-branching 和 engineering:github-pr-merge 會將危險步驟交給此技能處理。

Individual skills in this repo

This repo contains 4 individual skills — each has its own dedicated page.

gener8v/gener8v.claude-skills.engineering

Find and run a project's test, lint, type-check, build and dev-server commands, read the results correctly, and seed a throwaway database when UI work needs realistic data. Never seeds the project's real or default database. Use before 'run the tests', 'lint this', 'does it build', 'start the app so I can see it', 'seed some demo data', and before you claim that a change works. Not for deployment or CI pipeline design; use the project's own deploy tooling for those.

gener8v/gener8v.claude-skills.engineering

Create or top up a project's documentation set: list what exists, let the user choose which document types to add, collect one shared fact sheet from the code, write the documents (in parallel when there are several), then check them against each other and against the code. Use when asked to 'bootstrap the docs', 'start the documentation', 'we have no README or ARCHITECTURE', or 'fill in the missing docs'. Not for the per-commit update of existing documents (documentation-sync), and not for gener8v pipeline documents (gener8v:brownfield and gener8v:planning make those).

gener8v/gener8v.claude-skills.engineering

Before a commit, find every document that describes what the change touched and update it in the same commit, or confirm in one line that no document needs a change. Catches stale text, missing documentation and facts kept in two places. Use before any commit or PR, and when asked 'are the docs up to date', 'update the docs for this change' or 'did I miss a README change'. Not for creating a documentation set or filling large gaps (documentation-bootstrap), and not for gener8v pipeline documents under .gener8v/, which the pipeline skills own.

gener8v/gener8v.claude-skills.engineering

Put work on the correct branch before the first edit. Finds the base branch, starts a well-named branch from the current remote tip, and sets up one worktree per agent for parallel work. Use at the start of any change to a tracked file, such as 'start on issue 42', 'fix this typo', 'set up branches for these three tickets', or before you start sub-agents that edit code. Not for opening or merging a PR (github-pr-merge) or for history rewrites and other risky git commands (git-safety).

相關技能