Skip to content

Commit aa1b6e4

Browse files
authored
feat(git-commit): ryoppippi版のreferences/とrevertability哲学を取り込みフッターを中立化 (#154)
1 parent 8fdbc52 commit aa1b6e4

5 files changed

Lines changed: 265 additions & 23 deletions

File tree

.agents/skills/git-commit-ja/SKILL.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@ user-invocable: true
55
allowed-tools: Bash, Skill
66
---
77

8-
Use /git-commit to perform the commit, but write the commit message description **in Japanese**.
8+
Use `/git-commit` to perform the commit (granularity, revertability, `git apply`
9+
staging, and references all apply unchanged). It also forwards any `--path` /
10+
`--push` arguments. The reference docs live under
11+
`.agents/skills/git-commit/references/` (this skill has none of its own).
912

10-
Example: `fix(alacritty): 起動時警告を消すため非推奨オプションを削除`
13+
## Language override (this skill takes precedence)
14+
15+
`/git-commit` instructs English commit messages. When this skill runs, **the
16+
following language rules override that** — re-confirm them right before writing each
17+
message:
18+
19+
- **type**: English Conventional Commits type (`feat`, `fix`, `docs`, `refactor`,
20+
`chore`, …).
21+
- **scope**: English (e.g. `alacritty`, `vim`, `git`).
22+
- **description**: 日本語で書く。What だけでなく Why を簡潔に。
23+
24+
Example:
25+
26+
```
27+
fix(alacritty): 起動時警告を消すため非推奨オプションを削除
28+
```

.agents/skills/git-commit/SKILL.md

Lines changed: 72 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ user-invocable: true
55
allowed-tools: Bash
66
---
77

8-
Review current changes and autonomously commit following Conventional Commits.
8+
Review current changes and autonomously create fine-grained, independently
9+
revertable commits following Conventional Commits.
910

1011
**Working tree status (source repo):**
1112
```
@@ -19,32 +20,53 @@ Review current changes and autonomously commit following Conventional Commits.
1920

2021
## Arguments
2122

22-
If a `--path <dir>` argument is provided (e.g. invoked as `git-commit --path /tmp/feat-foo`), all git commands must be run inside that directory by prepending `cd <dir> &&` to every Bash command. This overrides the current working directory.
23-
24-
1. Run `git status`, `git diff`, and `git log --oneline -5` to understand the changes and context
25-
2. Decide the commit message autonomously
26-
3. Stage and commit using `git apply` (see below)
27-
28-
## Principle
29-
- Write **Why** in the subject line itself — keep it concise but meaningful.
30-
- Body is optional. If you feel a body is necessary, the commit is likely too large — consider splitting it.
31-
- Footer (Co-Authored-By) is always required.
32-
- Each commit must be **independently revertable** without breaking other functionality.
23+
- `--path <dir>`: run every git command inside `<dir>` by prepending `cd <dir> &&`
24+
to each Bash command. This overrides the current working directory (e.g. invoked
25+
as `git-commit --path /tmp/feat-foo`).
26+
- `--push`: push to remote after all commits are complete (default: off). See the
27+
**Push** section below.
28+
29+
1. Run `git status`, `git diff HEAD`, and `git log --oneline -10` to understand the
30+
changes and context
31+
2. Decide commit boundaries and messages autonomously
32+
3. Stage and commit each unit using `git apply --cached` (see below)
33+
34+
## Core Philosophy — Revertability First
35+
36+
Each commit must be **revertable independently** without breaking other
37+
functionality. Prefer smaller, granular commits over large groupings — split by
38+
hunks within files, not just whole files.
39+
40+
- **Tiny commits are expected.** A single review comment, one wording correction,
41+
one reference-file extraction, one symlink sync, or one formatting pass can each
42+
be its own commit when independently revertable. PR branches are squash-merged
43+
later, so don't worry about granularity being too fine.
44+
- **Tiny does not mean incomplete.** For moves, renames, or extractions, one commit
45+
must include *both* sides: remove/update the old location, add the new location,
46+
update references, and sync generated links. Never commit only the destination of
47+
a move while leaving the source/reference cleanup for later.
48+
- **Don't `--amend` away review history.** PR branches are squash-merged, so keep
49+
review fixes as small follow-up commits that can be reverted independently. Amend
50+
only for unpublished local mistakes or when the user explicitly asks.
51+
52+
For concrete good and bad examples, read `references/revertable-commits.md`.
3353

3454
## Commit Granularity
3555
- 1 commit = 1 logical change
3656
- Examine individual hunks, not entire files — split if needed
3757
- Separate refactoring and feature additions
3858
- Tests can be in the same commit as the main code
39-
- Formatting-only changes should be separate
59+
- Formatting-only changes should be separate (`chore(xxx): format` or `chore: format`)
4060

4161
## Staging with git apply
4262

43-
Never use interactive commands like `git add -p`. Instead:
63+
Never use interactive commands like `git add -p` or `git add --interactive`
64+
Claude Code cannot handle them. Instead:
4465

4566
```bash
46-
# 1. Generate patch for the target changes
47-
git diff > patch.diff
67+
# 1. Generate patch for the target changes (HEAD-relative so already-staged
68+
# hunks and new files from a prior iteration are not lost)
69+
git diff HEAD > patch.diff
4870

4971
# 2. Verify before applying (no file changes on failure)
5072
git apply --cached --check patch.diff
@@ -53,11 +75,16 @@ git apply --cached --check patch.diff
5375
git apply --cached patch.diff
5476
```
5577

78+
When a patch fails, needs whitespace handling, or must be staged without touching
79+
unrelated hunks, read `references/git-apply.md`.
80+
5681
## Commit Message Format
5782
Conventional Commits v1.0.0
5883

5984
Format: `type(scope): description`
60-
- scope: optional (e.g., `alacritty`, `vim`, `git`)
85+
- **type**: `feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `test`, `build`,
86+
`ci`, `chore`, `revert`
87+
- **scope**: optional (e.g., `alacritty`, `vim`, `git`)
6188
- **description: in English** — convey Why, not just What, but keep it short
6289

6390
Examples:
@@ -69,7 +96,31 @@ fix(git): remove deprecated option
6996
fix(git): remove deprecated option to prevent startup warning
7097
```
7198

72-
Required footer:
73-
```
74-
Co-Authored-By: Claude <noreply@anthropic.com>
75-
```
99+
Body is optional. Add one only to explain Why or revertability when the subject
100+
alone is insufficient. If a body is needed just to enumerate *what* changed, the
101+
commit is likely too large — consider splitting it.
102+
103+
Do not add a `Co-Authored-By` or any agent-identifying footer. This skill is shared
104+
across Claude / Codex / Cursor, so hardcoding a single agent name would mislabel
105+
commits made by the others.
106+
107+
## Quality Checks
108+
- Can this be reverted without breaking other functionality?
109+
- Is this the smallest logical unit?
110+
- Does the message clearly explain the change (Why)?
111+
- Does it match the project's commit patterns, scopes, and style?
112+
- No debugging statements or commented-out code without explanation
113+
114+
## Push (only if `--push`)
115+
116+
After all commits are complete, push to remote. Let repository git hooks run; if a
117+
pre-commit or pre-push hook runs format, sync, lint, typecheck, or tests, treat
118+
those as part of the normal validation path and fix any failures in a new small
119+
commit.
120+
121+
Never push to `main`/`master` directly — create a feature branch first.
122+
123+
If `--path <dir>` was also given, the push commands must run inside `<dir>` too —
124+
`references/push.md` shows where to prepend `cd <dir> &&`.
125+
126+
Read `references/push.md` for the exact branch/upstream checks and push commands.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Git Apply Reference
2+
3+
This skill stages patches **without touching the worktree**, so every command here
4+
uses `--cached` by default. Drop `--cached` only when you deliberately want to apply
5+
to the working tree instead of the index.
6+
7+
## Basic Usage
8+
9+
```bash
10+
# Always verify first before staging (no changes on failure)
11+
git apply --cached --check patch_file.patch
12+
13+
# Stage with verbose output for debugging
14+
git apply --cached -v patch_file.patch
15+
16+
# Stage a diff generated between refs
17+
git diff main...HEAD -- <file> | git apply --cached -v
18+
```
19+
20+
## Essential Flags
21+
22+
- `-v, --verbose`: always use this for detailed feedback during application.
23+
- `--check`: verify whether a patch can be applied cleanly without making changes.
24+
- `--cached`: stage the patch without applying it to the worktree.
25+
- `--stat`: display affected files before applying.
26+
- `--whitespace=fix`: automatically correct trailing whitespace issues.
27+
- `--reject`: create `.rej` files for failed sections instead of aborting entirely.
28+
- `--reverse` / `-R`: revert a previously applied patch.
29+
30+
## Troubleshooting Failed Applies
31+
32+
Trailing whitespace:
33+
34+
```bash
35+
git apply --cached --check --whitespace=fix patch_file.patch
36+
git apply --cached --whitespace=fix -v patch_file.patch
37+
```
38+
39+
Partial failures (write `.rej` files for the hunks that don't apply):
40+
41+
```bash
42+
git apply --cached --reject -v patch_file.patch
43+
```
44+
45+
Context mismatch — the surrounding lines in the file no longer match the patch
46+
context (line offsets / fuzz). Prefer a three-way merge, which uses the blob the
47+
patch was based on:
48+
49+
```bash
50+
git apply --cached --3way -v patch_file.patch
51+
```
52+
53+
If `--3way` is not viable, loosen the required context lines with `-C<n>` (e.g.
54+
`-C1`). Note: `--ignore-whitespace` only helps when the *only* difference in the
55+
context is whitespace — it does not fix genuine line-offset mismatches.
56+
57+
Line ending issues:
58+
59+
```bash
60+
git apply --cached --ignore-space-change -v patch_file.patch
61+
```
62+
63+
## Git Apply vs Git Am
64+
65+
- `git apply`: applies or stages changes without creating commits.
66+
- `git am`: applies patches with commit messages and author info preserved.
67+
68+
Use `git apply --cached -v` for this workflow to keep commit creation explicit and
69+
controlled.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Push Reference
2+
3+
Run in `sh`/`zsh` (this repo's shell). Do NOT use fish syntax.
4+
5+
When invoked with `--path <dir>`, prepend `cd <dir> &&` to every command below so
6+
the push targets that repository, not the current working directory.
7+
8+
## 1. Check the current branch before any push
9+
10+
```bash
11+
current_branch=$(git branch --show-current)
12+
if [ "$current_branch" = "main" ] || [ "$current_branch" = "master" ]; then
13+
echo "On $current_branch — stop. Create a feature branch before pushing."
14+
exit 1
15+
fi
16+
```
17+
18+
If the current branch is `main` or `master`, stop and create a feature branch
19+
before pushing. The `exit 1` above guarantees execution halts instead of falling
20+
through to the push step.
21+
22+
## 2. Check if the branch has an upstream
23+
24+
```bash
25+
git rev-parse --abbrev-ref --symbolic-full-name '@{u}'
26+
```
27+
28+
- **If this succeeds** (an upstream exists), push directly:
29+
30+
```bash
31+
git push
32+
```
33+
34+
- **If this fails** (no upstream), ask the user whether to set upstream and push:
35+
- If yes: `git push -u origin HEAD`
36+
- If no: skip pushing.
37+
38+
## 3. Hooks
39+
40+
Let repository git hooks run. If a pre-push hook runs format, sync, lint,
41+
typecheck, or tests and one fails, fix it in a new small commit and push again —
42+
treat hook failures as part of the normal validation path, not as errors to bypass.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Revertable Commit Examples
2+
3+
## Good: split independent implementation steps
4+
5+
```text
6+
feat(auth): add RefreshTokenService class
7+
8+
Added RefreshTokenService to handle token lifecycle management.
9+
This service generates and invalidates refresh tokens with
10+
configurable expiry periods.
11+
```
12+
13+
```text
14+
feat(auth): integrate token rotation in middleware
15+
16+
Updated auth middleware to call RefreshTokenService when validating
17+
tokens. This can be reverted independently without removing the
18+
service itself.
19+
```
20+
21+
## Good: keep both sides of a move together
22+
23+
One commit contains:
24+
25+
- `A .agents/skills/tdd/references/vitest-examples.md`
26+
- `M .agents/skills/tdd/SKILL.md`
27+
- `D .agents/skills/tdd/vitest-example.md`
28+
29+
The commit is still small, but it is complete: the old path is removed, the new
30+
path is added, and every reference points to the new path.
31+
32+
## Bad: split one move across incomplete commits
33+
34+
First commit:
35+
36+
- `A .agents/skills/tdd/references/vitest-examples.md`
37+
38+
Second commit:
39+
40+
- `M .agents/skills/tdd/SKILL.md`
41+
- `D .agents/skills/tdd/vitest-example.md`
42+
43+
The first commit is not independently revertable because it leaves duplicate or
44+
unreachable guidance until the second commit lands.
45+
46+
## Good: one review comment per commit
47+
48+
If a reviewer says "run format before typecheck/test", one commit can update only
49+
that workflow wording and the matching always-on reminder. Keep unrelated examples,
50+
source docs, and typo fixes for separate commits.
51+
52+
## Bad: tidy broad commit
53+
54+
Avoid a commit that mixes:
55+
56+
- PR review workflow changes
57+
- TypeScript assertion guidance
58+
- OpenCode data-source corrections
59+
- Markdown fence formatting
60+
- Generated symlink sync
61+
62+
Even if each change is correct, reverting one concern would revert unrelated work.

0 commit comments

Comments
 (0)