Commit-editmsg
If you are writing scripts that generate commits, you might want to programmatically construct a message.
Instead of constructing a massive string for git commit -m, you can write your message into .git/COMMIT_EDITMSG (or a temporary file) and run git commit -F <filename>.
Instead of git commit -m "Fix bug" -m "Detailed explanation", you just run git commit, write:
Fix login timeout on slow networks
Increase the timeout from 5s to 30s and add retry logic. This resolves the issue where users with high latency would see repeated failures.
Then save & exit.
Most developers circumvent this process using the -m flag:
git commit -m "Fix bug in login flow"
The -m flag is convenient for short messages, but it completely bypasses the COMMIT-EDITMSG workflow. This means you also bypass the powerful features that come with it: templates, hook validation, and multi-line editing.
You can bypass commit-msg hooks with --no-verify: COMMIT-EDITMSG
git commit --no-verify -m "Hotfix for production"
Warning: Use sparingly. This is a nuclear bypass for emergency situations.
| File | Purpose |
|------|---------|
| .git/COMMIT_EDITMSG | Active commit message being written |
| .git/MERGE_MSG | Auto-generated message for merge commits |
| .git/SQUASH_MSG | Message for squashed commits |
| .git/TAG_EDITMSG | Message for annotated tags |
| .git/description | Used by GitWeb (not for commit messages) |
We have all been there. You spend 10 minutes writing a detailed, perfectly formatted commit message. You save and close the editor... but the commit fails.
Maybe you forgot to stage a file, or a pre-commit hook rejected the code. If you are writing scripts that generate commits,
Git aborts the process. Your terminal screams error. Is your message gone?
No. It is saved in .git/COMMIT_EDITMSG.
The Fix: Instead of rewriting the message, simply run:
git commit -F .git/COMMIT_EDITMSG
This tells Git: "Use the content of that file as the message and try again." Then save & exit
