Commit-editmsg Info
Now, if a developer tries to commit with a bad message, Git aborts. This doesn't just work for command-line commits; it works for GUI tools and IDEs because everything eventually writes to COMMIT-EDITMSG . Your project uses Jira (PROJ-123). You want every commit to include the ticket number, but you hate typing it. 30 seconds before you commit, you fetched the PROJ-123 branch.
# <type>(<scope>): <subject> (max 50 chars) # |<---- using Conventional Commits ---->| # # <body> Explain *what* and *why*, not *how*. (72 chars max) # # <footer> Any closing notes or breaking changes. # # --- Commits will be signed off with your user.email --- Now, every time you run git commit , your editor opens with this custom template inside COMMIT-EDITMSG . It acts as a checklist, dramatically improving consistency across teams. "Aborting commit due to empty commit message." You saved an empty file, or a file with only comments ( # ). Git reads COMMIT-EDITMSG , strips comments, and sees nothing. Fix: Run git commit again and write a message. Editor opens but COMMIT-EDITMSG is missing. Your $EDITOR environment variable is misconfigured, or your editor crashed. Check with echo $EDITOR . Fix: git config --global core.editor "nano" (or your preferred editor). A hook is rejecting my commit, but I need to bypass it. You can bypass commit-msg hooks with --no-verify : COMMIT-EDITMSG
When you run:
Using a prepare-commit-msg hook (a cousin that runs before the editor opens), you can read the branch name and append the ticket to COMMIT-EDITMSG : Now, if a developer tries to commit with
#!/bin/sh # .git/hooks/commit-msg message_file=$1 # This is the path to COMMIT-EDITMSG pattern="^(feat|fix|docs|style|refactor|test|chore)((.+))?: .+" You want every commit to include the ticket
Located in .git/hooks/commit-msg (or .git/hooks/commit-msg.sample to start), this script can read, validate, or even modify the COMMIT-EDITMSG file before the commit is finalized. You want every commit message to follow the Conventional Commits standard (e.g., feat: add login , fix: resolve null pointer ).