Community程式設計與開發github.com

alfathafp/portofolio-web-design

結構化 Git 工作流程實務。進行任何程式碼變更時使用。在提交、分支、解決衝突、將混亂的工作目錄拆分為乾淨的原子提交、開啟或審查拉取請求(PR)、推送至遠端,或需要跨多個並行串流組織工作時使用。在進行發佈、選擇語意化版本號、標籤或編寫更新日誌時使用。

portofolio-web-design 是什麼?

這個技能提供了一套完整的 Git 工作流程與版本控制實務,專為 AI 代理程式(如 Claude Code、Cursor、Codex)與開發者設計。它強化了主幹開發(Trunk-Based Development)作為預設策略,強調 main 分支應隨時保持可部署狀態,特性分支應短命(1-3 天內合併),並以原子提交(atomic commits)與描述性訊息作為紀律核心。技能說明中詳細介紹了提交模式、分支命名規範、變更範圍控制(目標 ~100 行/提交),以及如何透過 git worktrees 讓多個 AI 代理程式並行工作而不互相干擾。此外,它也涵蓋了語意化版本控制(SemVer)、發佈標籤(tagging)、人類可讀的更新日誌(changelog)撰寫,以及常見的 Git 除錯技巧(如 git bisect)與預提交檢查清單。此技能適用於所有依賴 Git 的專案,能有效提升程式碼變更的可管理性、可審查性與可逆性。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/alfathafp/portofolio-web-design/tree/HEAD/.agents/skills/git-workflow-and-versioning

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

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

說明文件

Git 工作流程與版本控制

概述

Git 是你的安全網。將提交視為存檔點,分支視為沙盒,而歷史紀錄視為文件。當 AI 代理程式以高速生成程式碼時,嚴謹的版本控制是讓變更保持可管理、可審查且可逆轉的機制。

使用時機

總是如此。每個程式碼變更都應透過 Git 流動。

核心原則

主幹開發(Trunk-Based Development,推薦)

保持 main 隨時可部署。在短命的特性分支上工作,並在 1-3 天內合併回主幹。長期存在的開發分支是隱藏成本——它們會發散、產生合併衝突,並延遲整合。DORA 研究一致顯示,主幹開發與高效能工程團隊相關聯。

main ──●──●──●──●──●──●──●──●──●──  (隨時可部署)
        ╲      ╱  ╲    ╱
         ●──●─╱    ●──╱    ← 短命特性分支 (1-3 天)

這是推薦的預設做法。使用 Git Flow 或長期分支的團隊可以將這些原則(原子提交、小變更、描述性訊息)調整為符合他們的分支模型——提交的紀律比特定的分支策略更重要。

  • 開發分支是成本。 分支每存在一天,就會累積合併風險。
  • 發佈分支是可接受的。 當你需要穩定一個發佈版本,同時 main 分支繼續前進時。
  • 功能旗標(Feature Flags)優於長期分支。 傾向於將未完成的功能部署在旗標後方,而不是將其保留在分支上數週。

1. 及早提交,頻繁提交

每個成功的增量都應有它自己的提交。不要累積大量未提交的變更。

工作模式:
  實作片段 → 測試 → 驗證 → 提交 → 下一個片段

不是這樣:
  實作所有功能 → 希望它能運作 → 巨大的提交

提交是存檔點。如果下一個變更破壞了某些東西,你可以立即還原到最後一個已知的良好狀態。

2. 原子提交

每個提交只做一個邏輯上的事情:

# 好的:每個提交都是自包含的
git log --oneline
a1b2c3d 新增帶有驗證的任務建立端點
d4e5f6g 新增任務建立表單元件
h7i8j9k 將表單連接到 API 並加入載入狀態
m1n2o3p 新增任務建立測試(單元 + 整合)

# 不好的:所有東西混在一起
git log --oneline
x1y2z3a 新增任務功能、修正側邊欄、更新依賴、重構工具函式

3. 描述性訊息

提交訊息應解釋為什麼,而不只是做了什麼:

# 好的:解釋意圖
feat: 在註冊端點新增電子郵件驗證

防止無效的電子郵件格式到達資料庫。
在路由處理器層級使用 Zod 結構驗證,
與 auth.ts 中現有的驗證模式一致。

# 不好的:描述了從 diff 就能看出的明顯內容
update auth.ts

格式:

<類型>: <簡短描述>

<選擇性的主體,解釋為什麼,而不是做了什麼>

類型:

  • feat — 新功能
  • fix — 錯誤修正
  • refactor — 既非修正錯誤也非新增功能的程式碼變更
  • test — 新增或更新測試
  • docs — 僅文件
  • chore — 工具、依賴、設定

4. 保持關注點分離

不要將格式化變更與行為變更混合。不要將重構與功能混合。每種類型的變更都應該是單獨的提交——理想情況下也是單獨的 PR:

# 好的:分離關注點
git commit -m "refactor: 將驗證邏輯提取到共用工具函式"
git commit -m "feat: 在註冊功能中新增電話號碼驗證"

# 不好的:混合關注點
git commit -m "重構驗證並新增電話號碼欄位"

將重構與功能開發分開。 重構變更和功能變更是不一樣的變更——請分別提交它們。這使得每個變更更容易審查、還原以及在歷史中理解。小的清理工作(如重新命名變數)可以在審查者判斷下包含在功能提交中。

5. 控制變更規模

每個提交/PR 的目標是約 100 行。超過約 1000 行的變更應拆分。請參閱 code-review-and-quality 技能中的拆分策略,了解如何分解大型變更。

~100 行  → 易於審查,易於還原
~300 行  → 對於單一邏輯變更而言是可接受的
~1000 行 → 應拆分為較小的變更

分支策略

特性分支

main (隨時可部署)
  │
  ├── feature/task-creation    ← 每個分支一個功能
  ├── feature/user-settings    ← 並行工作
  └── fix/duplicate-tasks      ← 錯誤修正
  • 從 main(或團隊的預設分支)分支出去
  • 保持分支短命(在 1-3 天內合併)——長期分支是隱藏成本
  • 合併後刪除分支
  • 對於未完成的功能,優先使用功能旗標而非長期分支

分支命名

feature/<簡短描述>   → feature/task-creation
fix/<簡短描述>       → fix/duplicate-tasks
chore/<簡短描述>     → chore/update-deps
refactor/<簡短描述>  → refactor/auth-module

使用 Worktree

為了讓 AI 代理程式並行工作,請使用 git worktree 同時執行多個分支:

# 為一個特性分支建立 worktree
git worktree add ../project-feature-a feature/task-creation
git worktree add ../project-feature-b feature/user-settings

# 每個 worktree 都是一個獨立的目錄,擁有自己的分支
# 代理程式可以並行工作而不互相干擾
ls ../
  project/              ← main 分支
  project-feature-a/    ← task-creation 分支
  project-feature-b/    ← user-settings 分支

# 完成後,合併並清理
git worktree remove ../project-feature-a

優點:

  • 多個代理程式可以同時處理不同的功能
  • 無需切換分支(每個目錄都有自己的分支)
  • 如果某個實驗失敗,刪除 worktree 即可——不會遺失任何東西
  • 在明確合併之前,變更都是隔離的

存檔點模式

代理程式開始工作
    │
    ├── 進行一個變更
    │   ├── 測試通過?→ 提交 → 繼續
    │   └── 測試失敗?→ 還原到最後一次提交 → 調查
    │
    ├── 進行另一個變更
    │   ├── 測試通過?→ 提交 → 繼續
    │   └── 測試失敗?→ 還原到最後一次提交 → 調查
    │
    └── 功能完成 → 所有提交形成一個乾淨的歷史

這個模式意味著你永遠不會遺失超過一個增量的工作。如果代理程式偏離正軌,git reset --hard HEAD 會帶你回到最後一個成功的狀態。

變更摘要

在任何修改之後,提供一個結構化的摘要。這使得審查更容易,記錄了範圍紀律,並揭示了非預期的變更:

所做的變更:
- src/routes/tasks.ts: 為 POST 端點新增驗證中介軟體
- src/lib/validation.ts: 使用 Zod 新增 TaskCreateSchema

我故意沒有觸碰的項目:
- src/routes/auth.ts: 有相似的驗證缺口,但不在本次範圍內
- src/middleware/error.ts: 錯誤格式可以改進(這是另一個任務)

潛在問題:
- Zod 結構很嚴格——會拒絕額外的欄位。請確認這是否為預期行為。
- 新增 zod 作為依賴項(gzip 壓縮後 72KB)——已在 package.json 中

這個模式能及早捕捉錯誤的假設,並為審查者提供變更的清晰地圖。「故意沒有觸碰的項目」部分尤其重要——它顯示了你執行了範圍紀律,並沒有進行未經授權的修改。

預提交衛生檢查

在每次提交之前:

# 1. 檢查你即將提交的內容
git diff --staged

# 2. 確保沒有機密
git diff --staged | grep -i "password\|secret\|api_key\|token"

# 3. 執行測試
npm test

# 4. 執行 linting
npm run lint

# 5. 執行型別檢查
npx tsc --noEmit

使用 git hooks 自動化這個過程:

// package.json (使用 lint-staged + husky)
{
  "lint-staged": {
    "*.{ts,tsx}": ["eslint --fix", "prettier --write"],
    "*.{json,md}": ["prettier --write"]
  }
}

處理自動生成檔案

  • 提交自動生成的檔案 只有在專案預期它們存在時(例如 package-lock.json、Prisma migrations)
  • 不要提交 建置輸出(dist/、.next/)、環境變數檔案(.env)或 IDE 設定(除非共享 .vscode/settings.json)
  • 建立 .gitignore 來涵蓋:node_modules/、dist/、.env、.env.local、*.pem

使用 Git 進行除錯

# 找出哪個提交引入了錯誤
git bisect start
git bisect bad HEAD
git bisect good <已知良好的提交>
# Git 會簽出中間提交;在每個點執行你的測試來縮小範圍

# 檢視最近變更的內容
git log --oneline -20
git diff HEAD~5..HEAD -- src/

# 找出誰最後修改了特定行
git blame src/services/task.ts

# 搜尋包含特定關鍵字的提交訊息
git log --grep="validation" --oneline

發佈與版本控制

提交是你個人追蹤變更的方式;版本是你消費者追蹤變更的方式。一旦有任何東西依賴你的程式碼——另一個團隊、一個已發佈的套件、一個已部署的客戶端——「主線最新版」就不再是「我正在執行哪個版本,以及升級是否安全?」這個問題的充分答案。一個版本號碼和一份更新日誌就是回答這個問題的合約。

語意化版本控制

對於任何有消費者的東西,使用 MAJOR.MINOR.PATCH 版本號,並讓數字符號承載意義:

  MAJOR  破壞性變更 —— 消費者必須修改他們的程式碼才能升級
  MINOR  新增功能,向後兼容 —— 可以安全升級
  PATCH  錯誤修正,向後兼容 —— 可以安全升級

這個數字是一個承諾,所以請讓程式碼符合它。一個「補丁」卻改變了消費者依賴的行為,就是一個偽裝成補丁的重大變更(海勒姆定律——請參閱 api-and-interface-design 技能)。當不確定某個變更是否為破壞性時,假設它是;一個意外的重大版本比一個損壞的消費者便宜得多。

標籤發佈,並讓標籤成為事實來源

發佈是歷史中的一個不可變更的點,而不是一個移動的分支。為它標籤,以便總是可以重現:

git tag -a v1.4.0 -m "發佈 1.4.0"
git push origin v1.4.0

從標籤衍生出版本號碼,而不是在分散的檔案中手動編輯,這樣成品、標籤和更新日誌就永遠不會不一致。

為人類維護一份更新日誌

更新日誌不是 git log。它是經過策劃的、面向消費者的「變更了什麼以及我需要關心嗎?」的答案——按 Added / Changed / Fixed / Deprecated / Removed / Security 分組,最新的在最上面,每個條目都圍繞使用者影響來措辭,而不是內部機制。

## [1.4.0] - 2025-06-12
### Added
- 透過 CSV 進行大量任務匯入
### Fixed
- 週期性任務截止日期的時區偏移問題
### Deprecated
- `GET /v1/tasks/all` —— 請使用分頁的 `GET /v1/tasks`(將在 2.0 中移除)

在進行變更的同一提交中撰寫條目,趁影響猶新時進行——而不是在發佈時從提交考古學中重建。破壞性變更需要包含遷移說明和棄用窗口(遵循 deprecation-and-migration 技能);實際發佈是 shipping-and-launch 技能的工作——本節是提供給它的版本控制合約。

常見的合理化藉口

合理化藉口現實
「功能完成後我就會提交」一個巨大的提交不可能被審查、除錯或還原。提交每個片段。
「訊息不重要」訊息就是文件。未來的你(以及未來的代理程式)會需要理解變更了什麼以及為什麼。
「我會之後再 squash 所有東西」Squashing 會摧毀開發敘事。最好從一開始就進行乾淨的增量提交。
「分支會增加開銷」短命分支是免費的,並防止衝突的工作碰撞在一起。長期分支才是問題——在 1-3 天內合併。
「我會之後再拆分這個變更」大型變更更難審查,部署風險更高,也更難還原。在提交之前而不是之後拆分。
「我不需要 .gitignore」直到包含生產機密的 .env 被提交。立即設定它。
「只是一個小修正,bump 補丁版本」檢查消費者能觀察到什麼。他們依賴的行為變更是重大變更,無論 diff 大小。
「更新日誌就是提交日誌」提交是為你準備的;更新日誌是為消費者準備的,按影響進行策劃。從原始提交生成它會埋沒重要的東西。
「我們會在發佈時再寫更新日誌」到那時影響是從記憶中重建的,一半都會遺失。在進行變更時就撰寫條目。

紅旗警訊

  • 大量未提交的變更在累積
  • 像 "fix"、"update"、"misc" 這樣的提交訊息
  • 格式化變更與行為變更混合
  • 專案中沒有 .gitignore
  • 提交 node_modules/、.env 或建置產物
  • 與 main 分支顯著發散的長期分支
  • 強制推送到共享分支
  • 破壞性變更以次要或補丁版本號發佈
  • 一個發佈沒有標籤,或版本號碼手動編輯而與標籤不一致
  • 一個面向使用者的發佈沒有更新日誌條目,或更新日誌只是轉存的提交訊息

驗證清單

對於每個提交:

  • 提交只做一個邏輯上的事情
  • 訊息解釋了為什麼,遵循類型慣例
  • 提交前測試透過
  • diff 中沒有機密
  • 沒有將僅格式化的變更與行為變更混合
  • .gitignore 涵蓋了標準排除項

對於每個發佈(任何有消費者的):

  • 版本號碼的提升與變更相符:破壞性 → major,新增性 → minor,修正 → patch
  • 發佈已標籤,版本號碼從標籤衍生,而非手動編輯而不同步
  • 更新日誌有一個針對此版本按影響分組的、經過策劃的人類可讀條目

Individual skills in this repo

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

alfathafp/portofolio-web-design

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).

alfathafp/portofolio-web-design

Tests in real browsers via Chrome DevTools MCP. Use when building or debugging anything that runs in a browser. Use when you need to inspect the DOM, capture console errors, analyze network requests, profile performance, or verify visual output with real runtime data. Requires the chrome-devtools MCP server to be configured.

alfathafp/portofolio-web-design

Automates CI/CD pipeline setup. Use when setting up or modifying build and deployment pipelines. Use when you need to automate quality gates, configure test runners in CI, or establish deployment strategies.

alfathafp/portofolio-web-design

Conducts multi-axis code review. Use before merging any change. Use when reviewing code written by yourself, another agent, or a human. Use when you need to assess code quality across multiple dimensions before it enters the main branch. Use when asked to review a diff or a pull request, even when the diff is pasted inline.

alfathafp/portofolio-web-design

Simplifies code for clarity. Use when refactoring code for clarity without changing behavior. Use when code works but is harder to read, maintain, or extend than it should be. Use when reviewing code that has accumulated unnecessary complexity.

alfathafp/portofolio-web-design

Establishes a project's quality bar as a written contract and stops agents quietly lowering it. Interviews the user on which dimensions matter, supplies sane default thresholds when they have no number in mind, records everything in CONSTRAINTS.md, and watches the diff for a weakened bar — new @ts-ignore or eslint-disable suppressions, skipped or deleted tests, assertions stripped out, unimplemented stubs, thresholds edited down. Use when no quality bar is written down, when the user says "set up constraints" or "define our standards", when the user wants dimensions they care about — accessibility, web performance, coverage — set up as enforced constraints, when an agent keeps silencing checks or skipping tests to get to green, when you need a coverage or performance threshold and don't know what number to pick, or when an agent writes more code than anyone will read.

alfathafp/portofolio-web-design

Optimizes agent context setup. Use when starting a new session, when agent output quality degrades, when switching between tasks, or when you need to configure rules files and context for a project.

alfathafp/portofolio-web-design

Guides systematic root-cause debugging. Use when tests fail, builds break, something that worked yesterday broke, behavior doesn't match expectations, or you encounter any unexpected error. Use when you need to figure out what broke and why — a systematic approach to finding and fixing the root cause rather than guessing.

alfathafp/portofolio-web-design

Deploy applications and websites to Vercel. Use when the user requests deployment actions like "deploy my app", "deploy and give me the link", "push this live", or "create a preview deployment".

alfathafp/portofolio-web-design

Manages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code.

alfathafp/portofolio-web-design

Use when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.

alfathafp/portofolio-web-design

Use when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies

alfathafp/portofolio-web-design

Records decisions and documentation. Use when you need to document an architecture decision (ADR) or the reasoning behind a design choice, when changing public APIs, shipping features, or when you need to record context that future engineers and agents will need to understand the codebase.

alfathafp/portofolio-web-design

Subjects every non-trivial decision to a fresh-context adversarial review before it stands. Use when you want every assumption cross-examined before proceeding, when stress-testing a plan for hidden failure modes, when correctness matters more than speed, when working in unfamiliar code, when stakes are high (production auth, security-sensitive logic, a high-stakes migration, irreversible operations), or any time a confident output would be cheaper to verify now than to debug later.

alfathafp/portofolio-web-design

Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available

alfathafp/portofolio-web-design

Use when implementation is complete, all tests pass, and you need to decide how to integrate the work

alfathafp/portofolio-web-design

Builds production-quality, accessible, responsive user-facing UIs. Use when building or modifying interfaces and pages, creating components, implementing layouts, meeting WCAG accessibility requirements, managing state, or when the output needs to look and feel production-quality rather than AI-generated.

alfathafp/portofolio-web-design

Refines raw ideas into sharp, actionable concepts through structured divergent and convergent thinking. Use when an idea is still vague, when you need to stress-test assumptions before committing to a plan, or when you want to expand options before converging on one. Triggers on "ideate", "refine this idea", or "stress-test my plan".

alfathafp/portofolio-web-design

Delivers changes incrementally in thin, verifiable slices. Use when implementing any feature or change that touches more than one file, or when picking up the next task from a plan. Use when rolling a change out behind a feature flag, when you're about to write a large amount of code at once, or when a task feels too big to land in one step.

alfathafp/portofolio-web-design

Guides stable API and interface design. Use when designing APIs, module boundaries, or any public interface. Use when creating REST or GraphQL endpoints, defining type contracts between modules, or establishing boundaries between frontend and backend.

相關技能