Commit-editmsg May 2026

Embrace the file. Learn its structure. Automate it with hooks. Scaffold it with templates. Enrich it with --verbose .

The next time you stage a set of changes, close your terminal, type git commit , and take 60 seconds to write a message inside that COMMIT_EDITMSG buffer. Look at the diff. Write a subject line. Write a body. Save. Close.

#!/bin/bash COMMIT_MSG_FILE=$1 if ! grep -q "^Co-authored-by:" "$COMMIT_MSG_FILE"; then echo "" >> "$COMMIT_MSG_FILE" echo "Co-authored-by: Jane Doe <jane@example.com>" >> "$COMMIT_MSG_FILE" fi COMMIT-EDITMSG

git commit --amend This opens the COMMIT_EDITMSG for the previous commit. Edit the typo. Save. Close. The --amend flag replaces the old commit with a new one using your edited message. During an interactive rebase ( git rebase -i ), you mark a commit as edit . Git stops and checks out that commit. You then run git reset HEAD^ to unstage files, stage partial changes, and run git commit . When you run git commit , the COMMIT_EDITMSG already contains the original commit message from the commit you are splitting. You can edit it to reflect the new, smaller change. git commit --verbose Try this: git commit --verbose (or -v ). Now look at your COMMIT_EDITMSG . Below the status comments, Git has appended the full diff of your staged changes, each line commented out with # .

Most developers never look inside this file. They see the editor window pop up, assume it’s just a blank text box, and type git commit -m "fix bug" . They are missing the point entirely. Embrace the file

If you want to master Git, you must first master the COMMIT-EDITMSG . This article will explore what it is, why it exists, how to customize it, and how to leverage its hidden features to become a more effective developer. At its core, COMMIT-EDITMSG is a temporary text file that Git creates in your local .git directory. Specifically, you can find it at .git/COMMIT_EDITMSG . When you run a command like git commit (without the -m flag), Git opens your default text editor and loads the contents of this file.

#!/bin/bash # .git/hooks/commit-msg COMMIT_MSG_FILE=$1 read -r subject < "$COMMIT_MSG_FILE" Regex pattern for a JIRA ticket pattern="^[A-Z]+-[0-9]+: .+" Scaffold it with templates

: If you abort a commit (e.g., by exiting your editor with an empty message), Git deletes the file. Do not manually edit COMMIT_EDITMSG while a commit is not in progress. Always let Git create and manage the file. Common Workflows Enhanced by COMMIT-EDITMSG Fixing a Typo in the Last Commit You commit with a typo. Instead of git commit --amend -m "new message" , use: