Steve Robbins
Steve Robbins

Reputation: 13812

Add date to git commit message automatically

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;

Upvotes: 10

Views: 7565

Answers (3)

hd1
hd1

Reputation: 34657

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

Upvotes: 35

cjc343
cjc343

Reputation: 3765

Not sure why you'd do that since commits are already timestamped, but something like:

THEDATE=`date`
git commit -m "... $THEDATE"

would do so. Note that the double-quotes are important.

Upvotes: 2

madhead
madhead

Reputation: 33412

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

Upvotes: 4

Related Questions