For advice or a FREE quote




COMMIT-EDITMSG is a temporary file used by Git to store your commit message while you are writing it in an editor. This file is located at .git/COMMIT_EDITMSG within your project's root directory. 🛠️ How it Works When you run git commit without the
flag, Git opens your default text editor (like Vim, Nano, or VS Code) and creates this temporary file. The Process
: Git populates the file with a list of staged files and instructions (prefixed with ) to help you write your message. The Completion
: Once you save and close the file, Git reads its contents, ignores any lines starting with 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
: Always leave a blank line between the subject and the body. Body (Wrap at 72 characters) : Use this space to explain you changed and , rather than you did it. The Server Side ✏️ Editing an Existing Message
If you realized you made a typo or want to improve a message after it was written, you can trigger the COMMIT-EDITMSG flow again using these commands: Amend the last commit git commit --amend to reopen the editor for the most recent commit. Edit multiple/older commits git rebase -i HEAD~n is the number of commits back) and change for the specific commits you want to edit. GitHub Docs ⚠️ Common Issues Editor won't close COMMIT-EDITMSG is a temporary file used by Git
: If your commit isn't finishing, ensure you have actually saved and COMMIT-EDITMSG tab or editor. Security Risk .git/COMMIT_EDITMSG
can sometimes contain sensitive information (like passwords accidentally typed into a commit message), ensure your directory is never publicly accessible on web servers. for these commit messages?
core.commentCharBy default, Git ignores lines starting with #. If your commit message needs to contain a hashtag (e.g., #coding), this causes issues. You can change the comment character in your global config: Now Git will ignore lines starting with ;
git config --global core.commentChar ";"
Now Git will ignore lines starting with ; and leave your # lines alone in the final commit.
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.
Great commits tell a story. They explain why a change was made, not just what changed. Good commit bodies might contain multiple paragraphs, bullet points, Signed-off-by trailers, or references to issue trackers. Trying to format this in a shell is a nightmare.
This site uses cookies to ensure the best experience. By continuing to use this website, you agree to their use. Learn more about our privacy policy