| ▲ | danudey 5 hours ago | |
A simpler way to do this, especially if you do tagging in your repositories, is to use `git describe`. For example:
The format is <the most recent tag>-<the number of commits since that tag>-g<the short git hash>-<dirty, but only if the repo is dirty>.If the repo isn't dirty, then the hash you get excludes that part:
If you're using lightweight tags (the default) and not annotated tags (with messages and signatures and etc) you may want to add `--tags` because otherwise it'll skip over any lightweight tags.The other nice thing about this is that, if the repo is not -dirty, you can use the output from `git describe` in other git commands to reference that commit: | ||
| ▲ | WorldMaker 4 hours ago | parent | next [-] | |
`git describe` is great. Also, if you don't feel ready to commit to tagging your repository you can start with the `--always` flag which falls back to just the short commit hash. The article's script isn't far from `git describe --always --dirty`, which can be a good place to start, and then it gets better as you start tagging. | ||
| ▲ | o11c 3 hours ago | parent | prev [-] | |
The one caveat to this is that you must perform a sufficiently-deep clone that you can actually reach the tag. | ||