简体   繁体   中英

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;

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM