Your Git history is full of messages like “update” and “fix stuff.” Now something is broken, and you can’t tell which change to inspect or safely undo. Better commit messages give future you a useful trail instead of a guessing game.
Ask your coding agent to make small, focused commits with a clear subject and a short explanation of why the change was made. Have it write messages from the actual staged changes, report tests honestly, and prepare a pull-request description before you merge. Then check its work: a convincing message is useful only if it matches the code.
What makes a commit message useful?
A commit is a saved change in your project’s history. Its message should help someone understand what changed without opening every file, and why the change was needed once they look closer.
Compare these:
update
fix: preserve draft text when saving fails
Keep the entered text visible after a failed save so users
can retry without typing their work again.
The second example names the change in the subject and explains the reason in the body. It doesn’t claim the fix was tested or that it covers every possible failure.
Aim for one logical change per commit. A save-error fix and an unrelated button redesign are easier to review separately. If a change needs code and a test for that code, they can belong together: the unit is the purpose, not a single file.
Git’s commit documentation describes the common format: a short first line, a blank line, and a more detailed explanation. Treat that as a useful writing habit, not a magic word limit. If the reason isn’t known, say so rather than inventing one.
Choose a format your agent can repeat
Conventional Commits is an optional naming convention that puts a type before the subject. Its feat: type identifies a new feature, and fix: identifies a bug fix. Other types are allowed, including docs: for documentation.
feat: add a retry button to failed saves
fix: keep draft text after a failed save
docs: explain how to restore a backup
The prefix helps you scan the history, but it does not make a vague message useful. fix: fix stuff still leaves future you with a mystery. The words after the prefix should name the actual change.
You can skip the convention if your project already has a style that works. A plain subject like Preserve draft text when saving fails is better than a correctly formatted message that says nothing.
The body is optional under the convention. Use it when it adds context: the problem being solved, a decision that might otherwise look odd, or a limitation someone should know before changing the code again. Keep implementation details that are obvious from the diff out of the way.
If you want an agent to try this routine with, you can try the zcode agent harness free.
Give the agent a commit routine
The key step is reviewing what is actually staged. Staging means selecting the changes Git will include in the next commit. According to the Git diff documentation, git diff --staged shows those selected changes against the current commit.
Paste this into your project’s agent instructions or give it with a task:
Work in small, logical steps.
After each small working step, make a commit if I have
authorized commits. Keep unrelated changes separate.
Before each commit:
- Check git status.
- Stage only the changes for this step.
- Read git diff --staged.
- Write a short subject describing the actual change.
- Add a body explaining why, using the task or other
available context. If the reason is unclear, ask me.
- Do not include unrelated files or secrets.
Run the relevant checks when available. Report the exact
checks and results. Never say tests passed unless you ran
them and observed them pass; say "not run" when applicable.
Show me the commit message and resulting commit ID.
Do not push, open a pull request, or merge unless asked.
If the agent finds existing staged work it didn’t create, tell it to stop and ask rather than include or remove it. Review the staged diff yourself when the change affects something sensitive.
A diff shows what changed; it doesn’t always reveal why. The agent should use your task description or ask for the missing reason, not manufacture a confident explanation.
Write a pull request future you can review
A pull request, or PR, is a proposed set of changes for review before merging. Its description gives the reader the bigger picture across its commits. Even if you work alone, write it for the version of you who no longer remembers the task.
Give your agent this template:
## What changed
- [Describe the changes]
## Why
- [Explain the problem or goal]
## How tested
- [Exact check and result, or "Not run" with reason]
## Risks or follow-up
- [Known limitations, migration needs, or "None known"]
## Screenshots
- [Before and after for visible changes, or "Not applicable"]
Ask the agent to check the PR’s actual changes, then fill this in without guessing. “Tests passed” is not enough: name the check and its result. If the agent could not run it, that belongs in the description too.
Screenshots help with visible changes, but they don’t prove the underlying behavior works. For a nonvisual change, “Not applicable” is fine.
If your agent runs on a GLM coding plan, here's 10% off GLM coding plans.
Find and undo a suspect change
When something breaks, start by scanning the commit subjects:
git log --oneline
The Git log documentation describes how to inspect history. Once you find a likely candidate, copy its commit ID and inspect it:
git show COMMIT_ID
Replace COMMIT_ID with the ID from your own history. A promising message is a lead, not proof that the commit caused the problem.
If you’ve checked the change and want to reverse it, git revert COMMIT_ID creates a new commit that reverses the earlier change. Review the result and test it: later work may depend on the original change, and conflicts can need resolution. Git’s revert documentation also notes that the working tree should be clean before a normal revert. Don’t use a merge commit as your first practice run; those need extra care.
If you know a past commit worked and the current one is broken, git bisect can narrow the search. Save your work first, then start with:
git bisect start
git bisect bad
git bisect good GOOD_COMMIT_ID
Replace GOOD_COMMIT_ID with a commit you’ve verified works. Test each version Git selects and mark it with git bisect good or git bisect bad. Use git bisect skip if you can’t test one. When finished, run git bisect reset to return to where you started.
The screenshot checklist
- Each commit covers one logical change
- The subject says what changed
- The body explains why, when that context helps
- The agent checked the staged diff
- No unrelated files or secrets were included
- Test commands and results are accurate
- The PR lists changes, reasons, risks, and screenshots
- The code and message were reviewed before merging
You don’t need to rename your old history to start. Apply the routine to the next change, then use git log --oneline to see whether its subject tells you enough to find it again.
There's more on our blog on working with coding agents.
If this saved you time, a tip in $WURK helps us keep writing these.






Latest comments
0