Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bunam/1ab211299e5bb01a7ba45a3e38ce6b44 to your computer and use it in GitHub Desktop.
Save bunam/1ab211299e5bb01a7ba45a3e38ce6b44 to your computer and use it in GitHub Desktop.
git hook for revision and branch version file
#!/bin/bash
## Automatically generate a file with git branch and revision info
##
## Example:
## [master]v2.0.0-beta-191(a830382)
## Install:
## cp git-create-revisioninfo-hook.sh .git/hooks/post-commit
## cp git-create-revisioninfo-hook.sh .git/hooks/post-checkout
## cp git-create-revisioninfo-hook.sh .git/hooks/post-merge
## chmod +x .git/hooks/post-*
FILENAME='public/gitrevision.txt'
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`
VERSION="[$branch]$latesttag-$revcount($shorthash)"
echo $VERSION > $FILENAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment