Insert a piece of earlier vcs commits in your current commit message
Emacs Lisp
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
LICENSE
git-msg-prefix.el
git-msg-prefix.gif
readme.org

readme.org

git-msg-prefix.el

What

In many organizations, git commits have to have a structure, like starting with one word from a list (Add, Fix, Clean, Remove…).

In other projects, you should start the commit messages with the issue number, or a specific tag referring to the feature you’re developing (Billing-123).

git-msg-prefix is intended to solve this repetitive task, by providing a prompt with some customized list of options. The default command is to present a searchable list of the previous commits (more recent first), and lets you select the one you want. This list of candidates is configurable via `git-msg-prefix-log-command`.

Once selected, the relevant part of the commit line will be extracted from the choosen candidate (via the regex in git-msg-prefix-regex, and the matched text will be inserted in the current buffer.

A gif is worth a 10^3 words: ./git-msg-prefix.gif

Release post in my blog.

How

Install

This package will be in melpa shortly. For now, get it from https://github.com/kidd/git-msg-prefix.el

(use-package git-msg-prefix
  :ensure t
  :config
  (setq git-msg-prefix-log-flags " --since='1 week ago' "
        git-msg-prefix-input-method 'helm-comp-read)
  (add-hook 'git-commit-mode-hook 'git-msg-prefix))

Usage

Add a hook to activate run the function when starting to write your commit

(add-hook 'git-commit-mode-hook 'git-msg-prefix)
(setq git-msg-prefix-input-method 'helm-comp-read)

Otherwise, add a keybinding to that function or run it manually from the minibuffer.

(local-set-key
 (kbd "C-c i")
 'git-msg-prefix)

Configure

There are 3 variables to configure:

  • git-msg-prefix-log-command: defaults to “git log –pretty=format:"%s"”
  • git-msg-prefix-log-flags: defaults to “”
  • git-msg-prefix-regex: defaults to “^\([^ ]*\) ”
    • git-msg-prefix-input-method: defaults to ido-completing-read. Change it to your favourite input method. (‘completing-read ‘ido-completing-read ‘git-msg-prefix-helm-read ‘ivy-read)

Who

Raimon Grau <raimonster@gmail.com>