Skip to content

Instantly share code, notes, and snippets.

@dmstern
Last active December 18, 2023 21:03
Show Gist options
  • Save dmstern/d02ea41d4b0171ff2f4661daaa3e3f86 to your computer and use it in GitHub Desktop.
Save dmstern/d02ea41d4b0171ff2f4661daaa3e3f86 to your computer and use it in GitHub Desktop.
Git: pre-fill commit message with Jira Issue Id/title and re-use last commit message (also works with VSCode)
# located in .git/config:
# VSCode will use this to prefill the git commit message box.
[commit]
template = .git/.gitmessage.txt
#!/bin/sh
# .git/hooks/post-checkout
# Writes the Jira Id + Jira summary from the recently checked out branch name to the git commit template.
#########################################################################################################
printf "`git rev-parse --abbrev-ref HEAD | sed 's/-/❤/' | sed -E 's/[-|_]+/ /g' | sed 's/❤/-/'`" > .git/.gitmessage.txt
#!/bin/sh
# .git/hooks/post-commit
# re-use last commit message
#########################################################
printf "`git log -1 --pretty=%s`" > .git/.gitmessage.txt
[
{
"key": "ctrl+shift+g u", // Or what ever fits for you
"command": "git.restoreCommitTemplate"
},
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment