跳到主内容
智客 ZICQ

技能库 智客分类:Agent 工作流 git-workflow-and-versioning

Git Workflow And Versioning

结构git工作流程实践. 修改代码时使用 。 在承诺、分化、解决冲突、将混乱的工作树上的未承诺工作分割成干净的原子时使用,打开或审查牵引请求(PR),向远程推进,或需要组织跨越多个平行流的工作。 剪切发布时使用,选择语义版本的凸起,标记,或写入更改日志.

74275 安装量

官方网址:GitHub

技能介绍

先看中文介绍;官方 description 原文单独保留,不改写 SKILL.md。

做什么

Git工作流程做法

何时用

永远 每个代码更改都流经 git

代理如何加载

按 Agent Skills 渐进披露:启动时只加载 name 与 description(约 100 token);任务匹配后才读入整份 SKILL.md 正文;scripts/、references/、assets/ 仅在需要时再读。 本文件正文结构:Git Workflow and Versioning、Overview、When to Use、Core Principles、Trunk-Based Development (Recommended)、1. Commit Early, Commit Often。 其中含规范建议的小节:分步指令。

文件分析

文件分析:这是一份仅含 SKILL.md 的指令型技能,代理激活后整份正文进入上下文。

官方 description(原文)

Structures git workflow practices. Use when making any code change. Use when committing, branching, resolving conflicts, splitting uncommitted work in a messy working tree into clean atomic commits, opening or reviewing a pull request (PR), pushing to a remote, or when you need to organize work across multiple parallel streams. Use when cutting a release, choosing a semantic version bump, tagging, or writing a changelog.

Git Workflow and VersioningOverviewWhen to UseCore PrinciplesTrunk-Based Development (Recommended)1. Commit Early, Commit Often2. Atomic CommitsGood: Each commit is self-containedBad: Everything mixed together3. Descriptive MessagesGood: Explains intentBad: Describes what's obvious from the diff

来源分类:GitHub skill skills.sh agent-skill

SKILL.md 与 Agent 调用

官方规范 ↗
name
git-workflow-and-versioning
description
Structures git workflow practices. Use when making any code change. Use when committing, branching, resolving conflicts, splitting uncommitted work in a messy working tree into clean atomic commits, opening or reviewing a pull request (PR), pushing to a remote, or when you need to organize work across multiple parallel streams. Use when cutting a release, choosing a semantic version bump, tagging, or writing a changelog.
  1. 发现技能客户端向 Agent 提供名称与描述目录。
  2. 匹配与调用用户指定或任务匹配后,载入 SKILL.md 指令。
  3. 按需加载按步骤读取参考文档、使用脚本与素材。

具体调用语法与可用工具以目标 Agent 客户端为准。 查看调用机制说明 ↗

安装这个技能

Skills CLI ↗

先选择目标 Agent 和安装范围,保留技能包的附属文件,安装后检查客户端能否发现该技能。

交给 Agent 安装

复制安装指令给支持 Agent Skills 的代理,确认其中的目标目录与客户端匹配。

把 Agent Skill「git-workflow-and-versioning」安装到我的项目:SKILL.md 原文与官方 description 见 https://zicq.com/zh/skills/skl-727c3c347cc1bf4f-Git-%E5%B7%A5%E4%BD%9C%E6%B5%81%E7%A8%8B%E5%92%8C%E7%89%88%E6%9C%AC.html
请存为 .cursor/skills/git-workflow-and-versioning/SKILL.md 或 .claude/skills/git-workflow-and-versioning/SKILL.md,frontmatter 的 name 与 description 保持原样,不要改写。

GitHub 完整包 ↗

终端安装 · Skills CLI

需要 Node.js 与 npx。先查看仓库技能列表,确认实际名称。

npx skills add 'https://github.com/addyosmani/agent-skills/tree/HEAD/skills/git-workflow-and-versioning' --list

npx skills add 'https://github.com/addyosmani/agent-skills/tree/HEAD/skills/git-workflow-and-versioning' --skill 'git-workflow-and-versioning'

CLI 会交互选择目标 Agent,默认安装到项目;用户级安装使用 -g。先通过查看命令核对仓库内容,再用 npx skills list 检查已安装技能。

阅读排版
--- name: git-workflow-and-versioning description: Structures git workflow practices. Use when making any code change. Use when committing, branching, resolving conflicts, splitting uncommitted work in a messy working tree into clean atomic commits, opening or reviewing a pull request (PR), pushing to a remote, or when you need to organize work across multiple parallel streams. Use when cutting a release, choosing a semantic version bump, tagging, or writing a changelog. --- # Git Workflow and Versioning ## Overview Git is your safety net. Treat commits as save points, branches as sandboxes, and history as documentation. With AI agents generating code at high speed, disciplined version control is the mechanism that keeps changes manageable, reviewable, and reversible. ## When to Use Always. Every code change flows through git. ## Core Principles ### Trunk-Based Development (Recommended) Keep `main` always deployable. Work in short-lived feature branches that merge back within 1-3 days. Long-lived development branches are hidden costs — they diverge, create merge conflicts, and delay integration. DORA research consistently shows trunk-based development correlates with high-performing engineering teams. ``` main ──●──●──●──●──●──●──●──●──●── (always deployable) ╲ ╱ ╲ ╱ ●──●─╱ ●──╱ ← short-lived feature branches (1-3 days) ``` This is the recommended default. Teams using gitflow or long-lived branches can adapt the principles (atomic commits, small changes, descriptive messages) to their branching model — the commit discipline matters more than the specific branching strategy. - **Dev branches are costs.** Every day a branch lives, it accumulates merge risk. - **Release branches are acceptable.** When you need to stabilize a release while main moves forward. - **Feature flags > long branches.** Prefer deploying incomplete work behind flags rather than keeping it on a branch for weeks. ### 1. Commit Early, Commit Often Each successful increment gets its own commit. Don't accumulate large uncommitted changes. ``` Work pattern: Implement slice → Test → Verify → Commit → Next slice Not this: Implement everything → Hope it works → Giant commit ``` Commits are save points. If the next change breaks something, you can revert to the last known-good state instantly. ### 2. Atomic Commits Each commit does one logical thing: ``` # Good: Each commit is self-contained git log --oneline a1b2c3d Add task creation endpoint with validation d4e5f6g Add task creation form component h7i8j9k Connect form to API and add loading state m1n2o3p Add task creation tests (unit + integration) # Bad: Everything mixed together git log --oneline x1y2z3a Add task feature, fix sidebar, update deps, refactor utils ``` ### 3. Descriptive Messages Commit messages explain the *why*, not just the *what*: ``` # Good: Explains intent feat: add email validation to registration endpoint Prevents invalid email formats from reaching the database. Uses Zod schema validation at the route handler level, consistent with existing validation patterns in auth.ts. # Bad: Describes what's obvious from the diff update auth.ts ``` **Format:** ``` : ``` **Types:** - `feat` — New feature - `fix` — Bug fix - `refactor` — Code change that neither fixes a bug nor adds a feature - `test` — Adding or updating tests - `docs` — Documentation only - `chore` — Tooling, dependencies, config ### 4. Keep Concerns Separate Don't combine formatting changes with behavior changes. Don't combine refactors with features. Each type of change should be a separate commit — and ideally a separate PR: ``` # Good: Separate concerns git commit -m "refactor: extract validation logic to shared utility" git commit -m "feat: add phone number validation to registration" # Bad: Mixed concerns git commit -m "refactor validation and add phone number field" ``` **Separate refactoring from feature work.** A refactoring change and a feature change are two different changes — submit them separately. This makes each change easier to review, revert, and understand in history. Small cleanups (renaming a variable) can be included in a feature commit at reviewer discretion. ### 5. Size Your Changes Target ~100 lines per commit/PR. Changes over ~1000 lines should be split. See the splitting strategies in `code-review-and-quality` for how to break down large changes. ``` ~100 lines → Easy to review, easy to revert ~300 lines → Acceptable for a single logical change ~1000 lines → Split into smaller changes ``` ## Branching Strategy ### Feature Branches ``` main (always deployable) │ ├── feature/task-creation ← One feature per branch ├── feature/user-settings ← Parallel work └── fix/duplicate-tasks ← Bug fixes ``` - Branch from `main` (or the team's default branch) - Keep branches short-lived (merge within 1-3 days) — long-lived branches are hidden costs - Delete branches after merge - Prefer feature flags over long-lived branches for incomplete features ### Branch Naming ``` feature/ → feature/task-creation fix/ → fix/duplicate-tasks chore/ → chore/update-deps refactor/ → refactor/auth-module ``` ## Working with Worktrees For parallel AI agent work, use git worktrees to run multiple branches simultaneously: ```bash # Create a worktree for a feature branch git worktree add ../project-feature-a feature/task-creation git worktree add ../project-feature-b feature/user-settings # Each worktree is a separate directory with its own branch # Agents can work in parallel without interfering ls ../ project/ ← main branch project-feature-a/ ← task-creation branch project-feature-b/ ← user-settings branch # When done, merge and clean up git worktree remove ../project-feature-a ``` Benefits: - Multiple agents can work on different features simultaneously - No branch switching needed (each directory has its own branch) - If one experiment fails, delete the worktree — nothing is lost - Changes are isolated until explicitly merged ## The Save Point Pattern ``` Agent starts work │ ├── Makes a change │ ├── Test passes? → Commit → Continue │ └── Test fails? → Revert to last commit → Investigate │ ├── Makes another change │ ├── Test passes? → Commit → Continue │ └── Test fails? → Revert to last commit → Investigate │ └── Feature complete → All commits form a clean history ``` This pattern means you never lose more than one increment of work. If an agent goes off the rails, `git reset --hard HEAD` takes you back to the last successful state. ## Change Summaries After any modification, provide a structured summary. This makes review easier, documents scope discipline, and surfaces unintended changes: ``` CHANGES MADE: - src/routes/tasks.ts: Added validation middleware to POST endpoint - src/lib/validation.ts: Added TaskCreateSchema using Zod THINGS I DIDN'T TOUCH (intentionally): - src/routes/auth.ts: Has similar validation gap but out of scope - src/middleware/error.ts: Error format could be improved (separate task) POTENTIAL CONCERNS: - The Zod schema is strict — rejects extra fields. Confirm this is desired. - Added zod as a dependency (72KB gzipped) — already in package.json ``` This pattern catches wrong assumptions early and gives reviewers a clear map of the change. The "DIDN'T TOUCH" section is especially important — it shows you exercised scope discipline and didn't go on an unsolicited renovation. ## Pre-Commit Hygiene Before every commit: ```bash # 1. Check what you're about to commit git diff --staged # 2. Ensure no secrets git diff --staged | grep -i "password\|secret\|api_key\|token" # 3. Run tests npm test # 4. Run linting npm run lint # 5. Run type checking npx tsc --noEmit ``` Automate this with git hooks: ```json // package.json (using lint-staged + husky) { "lint-staged": { "*.{ts,tsx}": ["eslint --fix", "prettier --write"], "*.{json,md}": ["prettier --write"] } } ``` ## Handling Generated Files - **Commit generated files** only if the project expects them (e.g., `package-lock.json`, Prisma migrations) - **Don't commit** build output (`dist/`, `.next/`), environment files (`.env`), or IDE config (`.vscode/settings.json` unless shared) - **Have a `.gitignore`** that covers: `node_modules/`, `dist/`, `.env`, `.env.local`, `*.pem` ## Using Git for Debugging ```bash # Find which commit introduced a bug git bisect start git bisect bad HEAD git bisect good # Git checkouts midpoints; run your test at each to narrow down # View what changed recently git log --oneline -20 git diff HEAD~5..HEAD -- src/ # Find who last changed a specific line git blame src/services/task.ts # Search commit messages for a keyword git log --grep="validation" --oneline ``` ## Release & Versioning Commits are how *you* track change; a **version** is how your *consumers* track it. The moment anything else depends on your code — another team, a published package, a deployed client — "latest on main" stops being a sufficient answer to "what am I running, and is it safe to upgrade?" A version number and a changelog are the contract that answers it. ### Semantic Versioning For anything with consumers, version `MAJOR.MINOR.PATCH` and let the number carry meaning: ``` MAJOR breaking change — consumers must change their code to upgrade MINOR new functionality, backward-compatible — safe to upgrade PATCH bug fix, backward-compatible — safe to upgrade ``` The number is a promise, so make the code match it. A "patch" that changes behavior consumers relied on is a major change wearing a disguise (Hyrum's Law — see the `api-and-interface-design` skill). When unsure whether a change is breaking, assume it is; a surprise major is far cheaper than a broken consumer. ### Tag the release, and let the tag be the source of truth A release is an immutable point in history, not a moving branch. Tag it so it can always be reproduced: ```bash git tag -a v1.4.0 -m "Release 1.4.0" git push origin v1.4.0 ``` Derive the version from the tag rather than hand-editing it in scattered files, so the artifact, the tag, and the changelog can never disagree. ### Keep a changelog written for humans A changelog is not `git log`. It's the curated, consumer-facing answer to "what changed and do I care?" — grouped by `Added / Changed / Fixed / Deprecated / Removed / Security`, newest on top, every entry phrased around user impact, not internal mechanics. ```markdown ## [1.4.0] - 2025-06-12 ### Added - Bulk task import via CSV ### Fixed - Timezone drift in recurring task due dates ### Deprecated - `GET /v1/tasks/all` — use the paginated `GET /v1/tasks` (removal in 2.0) ``` Write the entry in the same change that makes the change, while the impact is fresh — not reconstructed from commit archaeology at release time. Breaking changes get a migration note and a deprecation window (follow the `deprecation-and-migration` skill); shipping the actual release is the `shipping-and-launch` skill's job — this section is the versioning contract that feeds it. ## Common Rationalizations | Rationalization | Reality | |---|---| | "I'll commit when the feature is done" | One giant commit is impossible to review, debug, or revert. Commit each slice. | | "The message doesn't matter" | Messages are documentation. Future you (and future agents) will need to understand what changed and why. | | "I'll squash it all later" | Squashing destroys the development narrative. Prefer clean incremental commits from the start. | | "Branches add overhead" | Short-lived branches are free and prevent conflicting work from colliding. Long-lived branches are the problem — merge within 1-3 days. | | "I'll split this change later" | Large changes are harder to review, riskier to deploy, and harder to revert. Split before submitting, not after. | | "I don't need a .gitignore" | Until `.env` with production secrets gets committed. Set it up immediately. | | "It's just a small fix, bump the patch" | Check what consumers can observe. A behavior change they relied on is a major, whatever the diff size. | | "The changelog is just the commit log" | Commits are for you; the changelog is for consumers, curated by impact. Generating one from raw commits buries what matters. | | "We'll write the changelog at release time" | By then the impact is reconstructed from memory and half of it is missing. Write the entry with the change. | ## Red Flags - Large uncommitted changes accumulating - Commit messages like "fix", "update", "misc" - Formatting changes mixed with behavior changes - No `.gitignore` in the project - Committing `node_modules/`, `.env`, or build artifacts - Long-lived branches that diverge significantly from main - Force-pushing to shared branches - A breaking change shipped under a minor or patch version bump - A release with no tag, or a version number hand-edited out of sync with the tag - A user-facing release with no changelog entry, or a changelog that's just dumped commit messages ## Verification For every commit: - [ ] Commit does one logical thing - [ ] Message explains the why, follows type conventions - [ ] Tests pass before committing - [ ] No secrets in the diff - [ ] No formatting-only changes mixed with behavior changes - [ ] `.gitignore` covers standard exclusions For every release (anything with consumers): - [ ] The version bump matches the change: breaking → major, additive → minor, fix → patch - [ ] The release is tagged, and the version is derived from the tag, not hand-edited out of sync - [ ] The changelog has a curated, human-readable entry grouped by impact for this version

相关技能

Agent 工作流

Skill Creator

创造有效技能指南。 当用户想创造出新的技能(或更新现有的技能),以专业知识,工作流程,或工具集成来扩展克洛德的能力时,应该使用这种技能.

Agent 工作流

Clawdhub

使用ClawdHub CLI搜索,安装,更新并发布从taladhub.com的代理技能. 需要获取苍蝇上的新技能时使用,将安装的技能同步到最新版本或特定版本,或者发布 npm-instainddhub CLI 的新/更新的技能文件夹.

Agent 工作流

Agent Team Orchestration

管弦乐团多代理团队,任务设定周期,交接协议,审查工作流程. 使用时间: (1)建立2+特派员队伍,具有不同专业,(2)确定任务路线和生命周期(收录框_ spec_建设_审查_完成),(3)在特派员之间制定交接协议,(4)建立审查和质量关口,(5)管理特派员之间的交流和文物共享.

Agent 工作流

Superpowers

Spec-first,TDD,子代理驱动的软件开发工作流程. 当:(1)构建任何新功能或应用——触发脑暴_计划_子代理执行回路,(2)调试出一个bug或测试失败——触发系统性的根起过程,(3)用户说"让我们构建","帮助我计划","我想添加X",或"这个被打破",(4)完成一个功…