2 ms·
Some useful commands for making this more friendly: Get the number of commits with `git rev-list --count HEAD`. Get a label that uses the most recent tag plus
by chrismorgan 5y ago
Some useful commands for making this more friendly:
Get the number of commits with `git rev-list --count HEAD`.
Get a label that uses the most recent tag plus the number of commits since and the current commit hash with `git describe` (read its documentation, it’s got a few nice knobs to match whether you use unannotated tags, annotated tags, branches, &c.).
This sort of thing is used in Arch Linux packages based on Git repositories, things like this:
pkgver () {
cd the-git-repository
git describe --long 2>/dev/null | sed 's/\([^-]*-g\)/r\1/;s/-/./g' || \
printf "r%s.g%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}
… which will give you versions like “1.2.3.r45.gdeadbeef” for commit deadbeef which is 45 commits past the one tagged 1.2.3, or “1.2.3.r0.g01234567” for commit 01234567 which is tagged 1.2.3, or “r1234.gdeadbeef” where you have no tags and 1234 commits from the root(s) until HEAD which is at commit deadbeef.