Commit-editmsg Verified

The Complete Guide to COMMIT_EDITMSG

1. What is COMMIT_EDITMSG?

COMMIT_EDITMSG is a temporary file created by Git during the committing process. It resides in the .git directory of your project (at .git/COMMIT_EDITMSG).

, and uses the remaining text as your official commit message. 📝 Commit Message Best Practices To make the most of the editor that COMMIT-EDITMSG opens, follow the 50/72 Rule DEV Community Subject Line (50 characters max) : A brief summary of the change. Use the imperative mood (e.g., "Fix bug" instead of "Fixed bug"). Blank Line COMMIT-EDITMSG

Best Practices for Leveraging COMMIT-EDITMSG

  1. Always use the editor for non-trivial commits. If a change requires more than one sentence of explanation, run git commit without -m.
  2. Install a commit-msg hook in your team repository. It is the only way to enforce standards without relying on developer discipline. Store the hook in a hooks/ folder in your repo and use a script to symlink it into .git/hooks/ during setup.
  3. Customize your template globally. Use git config --global commit.template to inject your name, your employer’s required legal boilerplate, or a checklist.
  4. Learn to love --verbose. Make an alias: git config --global alias.ci "commit --verbose". Now git ci will always open a COMMIT_EDITMSG with the diff included.
  5. Never use -m with --amend. Always use git commit --amend to open the editor. This preserves the original formatting, trailers, and line wraps.
#!/bin/sh
# .git/hooks/commit-msg