23

How to set current date as git commit message?

3
  • 19
    Is there a particular reason you want to set the date as the commit message? After all, the commit already stores the date when it was committed.
    – Amber
    Jan 11, 2011 at 5:23
  • 4
    I totally agree with Amber. This information is already stored, so you might as well make all your commit messages say "a". It's shorter and easier, and stores just as much information.
    – Cascabel
    Jan 11, 2011 at 6:08
  • 1
    for what it's worth, this question ended up helping me because i wanted to include the date in a git alias (git today = git checkout -b w-${1-``date +\"%Y-%m-%d\"``}) (double backticks should be single, boo markdown)
    – drzaus
    Sep 5, 2014 at 14:15

3 Answers 3

44
git commit -m "`date`" filename
2
  • 5
    and if you want to format the date: date +\"%Y-%m-%d\" (in Windows, ymmv)
    – drzaus
    Sep 5, 2014 at 14:12
  • 4
    @KushalJayswal it does work with Git Bash on Windows 10. Just make sure you put the quotes properly: git commit -m "`date +\"%Y-%m-%d\"`"
    – F1iX
    Feb 18, 2019 at 9:44
21
git commit -m "`date`" # Wed Aug 28 10:22:06 CST 2019
git commit -m "`date +'%Y-%m-%d'`" # 2019-08-28
git commit -m "Updated: `date +'%Y-%m-%d %H:%M:%S'`" # Updated: 2019-08-28 10:22:06
current="`date +'%Y-%m-%d %H:%M:%S'`"
msg="Updated: $current"
git commit -m "$msg" # Updated: 2019-08-28 10:22:06
0

For Windows, this command works:

git commit -m "$(Get-Date)"  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.