Create ~/.gitmessage.txt :
It’s important to note that this location is relative to the repository’s work tree, and Git uses the command git rev-parse --git-dir to always find the correct directory, especially when working with advanced features like worktrees. The path to this file is passed as the sole parameter to certain Git hooks, such as the commit-msg hook, allowing those scripts to read and modify the message before the commit is finalized.
This public link is valid for 7 days and shares a thread, including any personal information you added. This link or copies made by others cannot be deleted. If you share with third parties, their policies apply. Can’t copy the link right now. Try again later.
While it might seem like a minor technical detail, COMMIT_EDITMSG is where you should practice good "Git hygiene" using the : COMMIT-EDITMSG
The true power of COMMIT_EDITMSG is unlocked when you stop seeing it as a dumb text file and start seeing it as a programmable interface. Using templates and hooks, you can automate formatting, enforce team standards, and eliminate repetitive chores.
Then reuse it by running git commit -F .git/COMMIT_EDITMSG .
: Git reads the file, strips out lines starting with # , creates the commit, and updates the file with your final message. Create ~/
Your commit-msg hook can read .git/COMMIT_EDITMSG and reject the commit if it doesn't match the regex:
By setting git config commit.template , you can pre-fill COMMIT_EDITMSG with a checklist or a specific format your team follows.
Sometimes, the interaction with COMMIT_EDITMSG breaks down. Here are the most common scenarios and how to fix them. This link or copies made by others cannot be deleted
If you the file, Git reads your written text, strips away the lines starting with # , and permanently binds that message to your new commit.
To write your message: Press to enter "Insert Mode," then type your message. To save and exit: Press Esc , type :wq , and press Enter . To abort the commit: Press Esc , type :q! , and press Enter . 2. Aborting a Commit on Purpose
: Git pauses its execution and launches your configured text editor (e.g., Vim, VS Code, Nano), passing the path .git/COMMIT_EDITMSG to it.
# <type>(<scope>): <subject> # |<---- Using a Maximum of 50 Characters ---->| # # Explain *why* this change is being made. Focus on the reasoning # behind the change, not the specifics of the code (which the diff # already shows). # # Use bullet points for multiple items: # * First detail about the change. # * Second detail, keeping lines to ~72 characters for readability. # # Add a "Signed-off-by" line as required by your project. # # --- COMMIT END --- # Types: feat, fix, docs, style, refactor, test, chore # For more information, see: https://www.conventionalcommits.org