Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Git Commit Message Template

Tags:

git

git-commit

How do I craft customized commit message template?

I would like to have something like:

# Short (50 chars or fewer) summary of changes

# More detailed explanatory text
like image 394
Juanito Fatas Avatar asked Aug 07 '15 08:08

Juanito Fatas


2 Answers

Add following to your ~/.gitconfig:

[commit]
  template = ~/.git-commit-message

enter image description here

Create ~/.git-commit-message file with following content:

# Short (50 chars or fewer) summary of changes

# More detailed explanatory text

Ref. commit.template in http://git-scm.com/docs/git-config

like image 78
Juanito Fatas Avatar answered Oct 03 '22 20:10

Juanito Fatas


The value in creating a custom commit template is that you can use it to remind yourself (or others) of the proper format and style when creating a commit message.

There are 3 easy steps you will need to set so that you can follow same format whenever you (or others) do commit using: git commit

1) You'll need to add your editors .exe file using git command

git config --global core.editor "your editor full path" (ex: C:/Windows/notepad.exe)

Note: Run git as administrator

2) Now add your template text in one file and save it at your preferred location( you can save it anywhere in your machine) using some name .txt (ex : commit_template.txt)

Your custom commit message may be like

Subject line (try to keep under 50 characters)

Multi-line description of commit,

feel free to be detailed.

[Ticket: X]

Resolves : #121, #12

3) Set your template as default and custom commit template by adding this command:

git config --global commit.template "path of txt file" (ex: D:/My Commit Template/commit_template.txt)

If your team has a commit-message policy, then putting a template for that policy on your system and configuring Git to use it by default can help increase the chance of that policy being followed regularly.

Thank You!

like image 36
Madhav Saraf Avatar answered Oct 03 '22 18:10

Madhav Saraf