The COMMIT-EDITMSG file is a transient, temporary file created by Git in the .git/ directory (specifically, .git/COMMIT_EDITMSG ) whenever you initiate a commit that requires an editor. Its sole purpose is to hold the for the commit currently in progress.
You won't just be making a commit. You'll be crafting a piece of your project’s story. And the humble COMMIT_EDITMSG is your pen.
Git then launches your system's default text editor and loads this file. Inside, you will see a blank space at the top for your message, followed by several lines starting with the # symbol. These commented lines list the files that are staged, unstaged, or untracked, serving as a helpful reference while you document your changes.
Your Repository/ └── .git/ ├── HEAD ├── config ├── index └── COMMIT-EDITMSG <-- Temporary commit message file COMMIT-EDITMSG
Closes #234
Because the COMMIT_EDITMSG file forces you out of the fast-paced command line and into a focused text editor, it is the perfect place to practice structured documentation. Following standard conventions ensures your project history remains clean and readable.
: Running git commit (without flags) automatically opens COMMIT_EDITMSG in your system's default editor (like Vim, Nano, or VS Code). The COMMIT-EDITMSG file is a transient, temporary file
Git hooks are scripts that run automatically before or after specific Git actions. The commit-msg hook operates directly on the COMMIT-EDITMSG file. Teams use this hook to build automated validation tools that scan the file before a commit goes live.
You can change the default text that appears in COMMIT-EDITMSG . Run git config commit.template to load a custom framework every time you commit, which helps teams maintain consistent documentation standards. Aborting a Commit
After making your changes, save the file and close the editor. Git will then update the commit message and amend the commit. You'll be crafting a piece of your project’s story
: Create a template file (e.g., ~/.gitmessage.txt ):
You can configure Git to use a custom template whenever you commit. This template prepopulates COMMIT_EDITMSG . git config --global commit.template ~/.gitmessage.txt Use code with caution.