Reputation: 8589
I need to include the date and time in all commit messages (this is for syncing with a project management tool). I currently have have the alias:
alias commitDate = "date +%Y-%m-%d-%H-%M"
Is there anyway to include this or any other variables in the commit message?
Upvotes: 5
Views: 9034
Reputation: 1515
Using an environment variable:
$ export COMMIT_TITLE=$(date)
$ git add commitfile.txt
$ git commit -m "$COMMIT_TITLE"
[master b5a9354] Sun, May 10, 2020 9:38:12 AM
1 file changed, 1 insertion(+)
create mode 100644 commitfile.txt
Upvotes: 3
Reputation: 104
You can specify the commit message on the command line directly via -m
option. So if you want to commit new changes you could type:
git commit -m "Your message" -m "`$commitDate`"
which would lead to following commit message, as your shell replaces the env var commitDate
with its value:
Your message
*current date*
Upvotes: 6