Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add date to git commit message automatically

Tags:

git

linux

bash

so I have an sh script that throws together some files then commits them to a git repo. How can I dynamically add the date to my commit message?

My .sh looks something like

// do things to files...
git add -u;
git commit -m 'generated files on <date here?>';
git push origin master;
like image 598
Steve Robbins Avatar asked Feb 07 '13 00:02

Steve Robbins


2 Answers

Just format the output of the date command and Bob's your uncle:

// do things to files...
git add -u;
git commit -m "generated files on `date +'%Y-%m-%d %H:%M:%S'`";
git push origin master
like image 120
hd1 Avatar answered Oct 04 '22 18:10

hd1


Why not use prepare-commit-msg or commit-msg git hooks? You can find stubs in your .git/hooks directory.

like image 24
madhead - StandWithUkraine Avatar answered Oct 04 '22 17:10

madhead - StandWithUkraine