Write a commit message for what you staged, not everything you edited

Write a commit message for what you staged, not everything you edited

●3
calendar_today ago β€’ schedule2 min read

Stop Your AI From Writing Commit Messages for Code You Didn't Stage


Suppose you add a todo validation test and tidy another test in the same file, then stage only the new test.

If your AI assistant writes a commit message describing both edits, the message promises a change that isn't in the commit. 😬

Agent Toolbox includes Good Commit, a reusable instruction file that tells an AI coding assistant to inspect the Git index before proposing a message. Below is a reproducible example using its small JavaScript demo.


πŸ§ͺ Try It in a Fresh Clone

You'll need:

  • Git
  • Node.js (to run the demo tests)
  • An AI assistant that can read files and run Git commands

No npm dependencies are required.

git clone https://github.com/zmo2s/agent-toolbox.git
cd agent-toolbox
git switch -c demo/partially-staged

1. Add a new test

Append this test to test/todo.test.js:

test("rejects an omitted title", () => {
  assert.throws(() => addTodo(), /Todo title is required/);
});

Stage that addition:

git add test/todo.test.js

2. Make a second edit, but don't stage it

Rename the first test from creates a todo to creates an incomplete todo, and leave that rename unstaged.

Both edits are in the same file, but only the new test belongs in the next commit.

3. Inspect both patches and run the tests

git status --short
git diff --cached
git diff
npm test

What to expect:

Command Should show
git status --short MM test/todo.test.js
git diff --cached Only the appended test (staged)
git diff Only the rename (unstaged)

πŸ’‘ In MM, the first M means staged changes and the second M means unstaged changes.

Test counts may change as the project grows.


πŸ€– Ask for a Commit Message

From inside the clone, send your assistant this prompt:

Read .codex/skills/good-commit/SKILL.md and propose a commit message for my current changes.

An illustrative subject line:

test(core): βœ… cover omitted todo titles

βœ… What a good response looks like

The assistant should:

  • Say that the proposal covers the staged test addition
  • Mention the unstaged test-name edit separately

The assistant should not:

  • ❌ Include the rename in the commit description
  • ❌ Restage the entire file
  • ❌ Create a commit just because you asked for a message

Exact wording may vary. The key check: does the message match git diff --cached?


πŸ” Reuse It in Your Own Project

  1. Copy the Good Commit skill into your repository at:
    .codex/skills/good-commit/SKILL.md
    
  2. Use the explicit prompt shown above.
  3. Want the /skill-commit shortcut? You'll also need the routing instructions from AGENTS.md.

⚠️ Note: The skill provides instructions, not a guarantee of model behavior. Always review the patch and the proposed message before committing.

You can try this workflow without installing the separate Security Guardian policy.


πŸ™Œ Help Improve the Examples

First-time contributors are welcome! Some ideas:

  • πŸ“ Document a breaking-change commit with migration guidance
  • πŸ”€ Show separate messages for unrelated changes

Before starting, check the existing issues and open PRs, and follow the contribution guide.

πŸ‘‰ Repo: github.com/zmo2s/agent-toolbox

1 Comment

0 votes
πŸ”₯ Join developers growing publicly
Share your knowledge, build in public, and grow your developer presence with a global community.

More Posts

The Sovereign Vault β€” A Comprehensive Guide to Protocol-Driven AI

Ken W. Algerverified - Jun 4

AAIF Hits 10 Projects. Its CTO on What to Adopt Now and the Security Gaps Left Open

Tom Smithverified - Oct 23

A Message From Our Founder: On the Winding Down of LaaSyβ„’

Ken W. Algerverified - Oct 29

Your AI Doesn't Just Write Tests. It Runs Them Too.

Kevin Martinez - May 12

MCP Is the USB-C of AI. So Why Are You Plugging Everything In?

Ken W. Algerverified - Jun 10
chevron_left
136 Points β€’ 3 Badges
France β€’ t.co/JbKzbXD2oX
1Posts
0Comments
Open-source developer building tools for VRChat communities
VR β€’ Web β€’ Automation β€’ AI

Related Jobs

View all jobs β†’

Commenters (This Week)

4 comments
3 comments
2 comments

Contribute meaningful comments to climb the leaderboard and earn badges!