We use gitlab issues at work, which supports tagging commit messages with an issue number, to make that commit appear in the issue thread. I often forget to tag my messages though, and then remember a second after committing.

So I wrote a little helper function as a custom git command:

#!/bin/sh

OLD_MSG=$(git log --format=%B -n1)
git commit --amend -m "$OLD_MSG, #$1"

It’s just a simple shell script that fetches the last commit message and appends the issue number. So I can do this:

$ git commit -m "add css grid support"
# ah fuck, forgot that this is related to an issue!
$ git append-issue 27
# commit msg is now: "add css grid support, #27"

To make it work:

  • Name the shell script git-append-issue (no extension)
  • save it in a folder in your home directory, i.e. ~/git-commands
  • make it executable with chmod 555
  • add that folder to your $PATH
  • git now recognizes your custom command!
  • 0
  • 0

No mentions yet.