Friday, October 30, 2020

Default Git Message as a Pre-Commit Reminder

If you want a reminder when you commit in Git that you need to do something before committing, such as generating the text equivalents of binary files (something I occasionally forget to do if I working on something that doesn't use Project Explorer, which automatically does that for me), do the following:

  • Create a text file anywhere you wish (named, for example, commit.txt) with the default message you want used in Git commits, such as “Remember to DO WHATEVER YOU NEED TO DO".
  • Open a command window in the project folder (the one that has .git as a subdirectory).
  • Type in a command window: git config commit.template “path\commit.txt”, where path is the full path for the text file you created.

Now, whenever you commit, the commit message defaults to “Remember to DO WHATEVER YOU NEED TO DO” (or whatever your message was), which of course you will then overwrite with the real commit message after you do what the reminder tells you to do.

No comments:

Post a Comment