Skip to content

Instantly share code, notes, and snippets.

@metal3d
Created July 11, 2023 13:37
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 metal3d/0934941c51a8511f0d7d0756c759b923 to your computer and use it in GitHub Desktop.
Save metal3d/0934941c51a8511f0d7d0756c759b923 to your computer and use it in GitHub Desktop.
Clean git version in your Makefile
# Get the current clean version from your git repo
# - -tagname if the current commit is tagged and no changes were detected
# - branchname-sha if not
# - branchname-sha-dirty if changes were detected and not commited
# Use $(VERSION) to get it, wherever you want in your commands
VERSION=$(shell \
git describe --exact-match --tags --dirty 2>/dev/null || \
printf "%s-%s%s" \
$(shell git branch --show-current) \
$(shell git log -n1 --pretty=%h) \
$(shell git diff --quiet || echo "-dirty") \
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment