I'm running this shell script whenever I do a git commit -m "msg"
which writes the commit log to a php file. I want it to include the current commit message as well that I am doing at that time.
My shell script:
#!/bin/sh
path="path/to/gitlog.php"
echo "<?php $git_log = array(" > $path
git log --date=iso --pretty=format:'array("%h","%an","%ad","%s"),' >> $path
echo ");" >> $path
The gitlog.php gets saved to my repository, which I will then git push
.
I currently have it in 'pre-commit' hook, is there a way to get the committing message within this hook?
My use case
I am the only developer in the project. Time is short! it's for others who are involved in the project to see progress and read the descriptive commit logs without the overhead of me having to double up. The log is output to a dashboard that everyone has access to.
Git is not running on the dashboard server, and files are deployed from a repository hosting company (Beanstalk)
git commit --amend
works), but you can't change the existing commit. If you're trying to include version information, the usual method with git is to keep that file outside git, especially if the entire file is generated from a commit (as this one would be). To view an old commit you check it out, then run your "generate version".commit-msg
hook. It's intended to let you alter the message (for formatting standards) or reject the commit if the message is wrong. I have never actually used this hook myself but it runs at the right point in the commit process. I would recommend not doinggit add .
(that might add files you are deliberately leaving modified-but-not-staged) butgit add $path
might well work here. (I'd suggest testing with commits of specific files as well, though, and/orgit commit -a
, to see if it works right there.)