Add date to git commit message automatically

so I have a sh script that dumps some files and then pushes them to a git repository. How can I dynamically add a date to a trade 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;

      

+3


source to share


3 answers


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



// do things to files...
git add -u;
git commit -m "generated files on `date +'%Y-%m-%d %H:%M:%S'`";
git push origin master

      

+13


source


Not sure why you would do this as the commits are already time stamped, but something like:

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

      



will do it. Please note that double quotes are important.

+2


source


Why not use prepare-commit-msg

or commit-msg

git hooks ? You can find the stubs in the directory .git/hooks

.

0


source







All Articles