granular-git
Skill2 starsChanged 3 months agoMITView on GitHub
Use this skill whenever an agent needs to commit a precise, character-level subset of file changes to a Git repository without disturbing the working directory. Triggers include: staging only part of a file's edits, committing one logical change while leaving other in-progress work untouched on disk, or when patch-based approaches (git apply, git add -p) are failing due to surrounding context drift. Uses Git plumbing commands (hash-object, update-index) to bypass the working directory entirely. Handles tracked files, untracked files that exist on disk, and brand-new files created purely from memory.
In this repository7 other files it gives its agents.
- amnesiaSkill
- atomic-commitsSkill
- changelogSkill
- lean-codeSkill
- orchestraSkill
- specularSkill
- state-machine-designSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 26
Read current index state if there are existing staged changes to preserve:
- Distinctive: line 74
Add Change B to target state, commit
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Granular Git
Stage and commit exact file content without touching the working directory.
Core Concept
Standard Git: Working Directory → Staging Area → Commit
This skill reverses the flow: the agent constructs the exact desired file state in memory and injects it directly into the Staging Area.
[Target State] → hash-object → update-index → commitThe physical file on disk is never modified.
Procedure
1. Determine Target State
Read current index state if there are existing staged changes to preserve:
git show :0:path/to/file.txtApply character-level edits to that string (not the disk file).
2. Write as Git Object
TARGET_SHA=$(printf '%s' "$TARGET_CONTENT" | git hash-object -w --stdin)3. Map to Index
For tracked files:
git update-index --cacheinfo 100644,"$TARGET_SHA","path/to/file.txt"For brand-new files:
git update-index --add --cacheinfo 100644,"$TARGET_SHA","path/to/file.txt"| Argument | When |
--add | Required for untracked files |
100644 | Regular files |
100755 | Executable files |
4. Commit
git commit -m "type(scope): description"Multi-Commit Pattern
For multiple independent changes in one file:
HEAD → Commit 1 (Change A) → Commit 2 (A+B) → Commit 3 (A+B+C)- Construct target state for Change A only
- Commit
- Add Change B to target state, commit
- Repeat for Change C
Safety Checklist
- Is Git initialized? —
git rev-parse --is-inside-work-tree - Existing staged changes? — Read via
git show :0:<file>and merge - Repo in clean state? — No ongoing merge/rebase
Advantages Over Patches
| Property | Patches | This Skill |
| Context sensitivity | Fails if context changed | Immune |
| Precision | Line-level | Character-level |
| Working directory | May modify | Never touches |
Example
File on disk has Bug fix + Refactor + Docs. You want to commit only the bug fix:
# 1. Read HEAD version
git show HEAD:src/utils.py
# 2. Create target state (HEAD + bug fix only)
TARGET_SHA=$(printf '%s' "$FIXED_CONTENT" | git hash-object -w --stdin)
# 3. Stage just the bug fix
git update-index --cacheinfo 100644,"$TARGET_SHA","src/utils.py"
# 4. Commit bug fix
git commit -m "fix: correct null pointer check"
# 5. Now repeat for refactor...Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

