Can git pre-commit hook add file to repo?

I save the text file of my git log in my working directory and I have a script that updates it after commit. This is great, but the effect of this is that the version inside the repo always has one commit.

Is it possible to write a pre-commit hook that will call the script and add the file to the repo, while actually saving the text version of the log with the current commit information inside it?

I am new to git hooks and have no idea how this will work, if possible. I appreciate the help!

+3
source share
2 answers

The short answer is no. The log contains a SHA1 commit, which depends on the contents of the commit. If you change the log, you will change the commit, and it will still be invalid.

I wonder why you are trying to do this, really. Inside the vault git logis as good as cat saved-git-log. If you want this to be a change for released versions, just create it as part of the build / deploy process, for example, something like this:

tarname=my-project-$(git describe HEAD).tar
git log > changelog.txt
git archive --format=tar HEAD > $tarname
tar -Af $tarname changelot.txt
gzip $tarname
+3
source

I just pull out the full logs from the Bitbucket / Github RSS feed. It seems like this would be the easiest way to achieve what you are asking for, especially when using Heroku.

+1
source

Source: https://habr.com/ru/post/1788634/


All Articles