Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
git hook for revision and branch version file
## Automatically generate a file with git branch and revision info
## Example:
## [master]v2.0.0-beta-191(a830382)
## Install:
## cp .git/hooks/post-commit
## cp .git/hooks/post-checkout
## cp .git/hooks/post-merge
## chmod +x .git/hooks/post-*
exec 1>&2
branch=`git rev-parse --abbrev-ref HEAD`
shorthash=`git log --pretty=format:'%h' -n 1`
revcount=`git log --oneline | wc -l`
latesttag=`git describe --tags --abbrev=0 --always`
Copy link

adrfantini commented May 14, 2020

@thom my usecase is actually similar, but you are right and I can actually do this at package creation time in the makefile: it's way cleaner and makes more sense. Thanks for the answer!

Copy link

marslo commented Jul 16, 2021

the post-commit hook will do: update ${FILENAME} every time after git commit -am <message>, so the "new" ${FILENAME} actually won't be published into remote repository due to the status is modified (instead of staged).

So, is there any way that using git-hook to modify files in post-commit steps, and put changed file into staged status (for push)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment