Skip to content

Instantly share code, notes, and snippets.

@finestructure
Created November 24, 2011 15:15
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 finestructure/1391557 to your computer and use it in GitHub Desktop.
Save finestructure/1391557 to your computer and use it in GitHub Desktop.
Bash script to report a git repositories version for further use like embedding as a version string
#!/bin/bash
git status
version=$(git describe --tags --dirty)
# version can be empty when there are no tags, use rev-parse in that case
# to log the last commit id
if [[ -z "$version" ]]; then
diff=$(git diff)
version=$(git rev-parse --short HEAD)
if [[ -n "$diff" ]]; then
version=${version}-dirty
fi
fi
echo version: $version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment