Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a Git hook to create a commit log and add to the current commit

Tags:

git

bash

shell

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)

like image 913
digout Avatar asked Dec 04 '15 21:12

digout


1 Answers

Another option could be to create an appropriate hook that writes the changelog to a file outside your repo, and then pushes the file to somewhere accessible by external users. No need to commit the changelog then, which is the cause of problems.

like image 107
Penguin Brian Avatar answered Oct 17 '22 14:10

Penguin Brian