File: git-commit.el.html

This package assists the user in writing good Git commit messages.

While Git allows for the message to be provided on the command line, it is preferable to tell Git to create the commit without actually passing it a message. Git then invokes the $GIT_EDITOR
(or if that is undefined $EDITOR) asking the user to provide the
message by editing the file ".git/COMMIT_EDITMSG" (or another file in that directory, e.g., ".git/MERGE_MSG" for merge commits).

When global-git-commit-mode is enabled, which it is by default, then opening such a file causes the features described below, to be enabled in that buffer. Normally this would be done using a major-mode but to allow the use of any major-mode, as the user sees fit, it is done here by running a setup function, which among other things turns on the preferred major-mode, by default text-mode.

Git waits for the $EDITOR to finish and then either creates the commit using the contents of the file as commit message, or, if the editor process exited with a non-zero exit status, aborts without creating a commit. Unfortunately Emacsclient (which is what Emacs users should be using as $EDITOR or at least as $GIT_EDITOR) does not differentiate between "successfully" editing a file and aborting; not out of the box that is.

By making use of the with-editor package this package provides both ways of finish an editing session. In either case the file is saved, but Emacseditor's exit code differs.

  C-c C-c Finish the editing session successfully by returning
           with exit code 0. Git then creates the commit using
           the message it finds in the file.

  C-c C-k Aborts the edit editing session by returning with exit
           code 1. Git then aborts the commit.

Aborting the commit does not cause the message to be lost, but relying solely on the file not being tampered with is risky. This package additionally stores all aborted messages for the duration of the current session (i.e., until you close Emacs). To get back an aborted message use M-p and M-n while editing a message.

  M-p Replace the buffer contents with the previous message
           from the message ring. Of course only after storing
           the current content there too.

  M-n Replace the buffer contents with the next message from
           the message ring, after storing the current content.

Support for inserting Git trailers (as described in the manpage git-interpret-trailers(1)) is available.

  C-c C-i Insert a trailer selected from a transient menu.

When Git requests a commit message from the user, it does so by having her edit a file which initially contains some comments, instructing her what to do, and providing useful information, such as which files were modified. These comments, even when left intact by the user, do not become part of the commit message. This package ensures these comments are propertizes as such and further prettifies them by using different faces for various parts, such as files.

Finally this package highlights style errors, like lines that are too long, or when the second line is not empty. It may even nag you when you attempt to finish the commit without having fixed these issues. The style checks and many other settings can easily be configured:

  M-x customize-group RET git-commit RET

Defined variables (27)

git-commit-cd-to-toplevel
git-commit-comment-headings
git-commit-elisp-text-mode-abbrev-table
git-commit-elisp-text-mode-hook
git-commit-elisp-text-mode-map
git-commit-elisp-text-mode-syntax-table
git-commit-finish-query-functions
git-commit-font-lock-keywords
git-commit-header-line-format
git-commit-known-pseudo-headers
git-commit-major-mode
git-commit-mode
git-commit-mode-hook
git-commit-mode-map
git-commit-mode-menu
git-commit-need-summary-line
git-commit-post-finish-hook
git-commit-post-finish-hook-timeout
git-commit-redundant-bindings
git-commit-setup-hook
git-commit-style-convention-checks
git-commit-summary-max-length
git-commit-trailers
git-commit-usage-message
git-commit-use-local-message-ring
global-git-commit-mode
global-git-commit-mode-hook

Defined functions (47)

git-commit--auto-fill-except-summary
git-commit--flyspell-verify
git-commit--goto-insert-position
git-commit--insert-ident-trailer
git-commit--insert-trailer
git-commit--insert-trailer-1
git-commit-ack
git-commit-cc
git-commit-check-style-conventions
git-commit-co-authored
git-commit-co-developed
git-commit-collapse-diff
git-commit-elisp-text-mode
git-commit-ensure-comment-gap
git-commit-extend-region-summary-line
git-commit-finish-query-functions
git-commit-get-ident
git-commit-insert-changelog-gnu[Arg list not available until function definition is loaded.]
git-commit-insert-changelog-plain[Arg list not available until function definition is loaded.]
git-commit-insert-header
git-commit-insert-trailer
git-commit-mode
git-commit-mode-menu
git-commit-modified
git-commit-next-message
git-commit-prev-message
git-commit-read-ident
git-commit-reported
git-commit-review
git-commit-run-post-finish-hook
git-commit-save-message
git-commit-search-message-backward
git-commit-search-message-forward
git-commit-self-ident
git-commit-setup-auto-fill
git-commit-setup-bug-reference
git-commit-setup-capf
git-commit-setup-changelog-support
git-commit-setup-flyspell
git-commit-setup-orglink
git-commit-signoff
git-commit-suggested
git-commit-test
git-commit-turn-on-auto-fill
git-commit-turn-on-flyspell
git-commit-turn-on-orglink
global-git-commit-mode

Defined faces (0)