2

I am still a newbie on git. When I did a git clone ... on any packages, it mostly downloads from the master branch.

My understanding is a master branch should contain both development and release codes.
If so, is it possible to find out the latest (production) release version from the downloaded master branch?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Mazilo
  • 69
  • 8

2 Answers2

3

If every release is marked with an annotated tag, git describe is what you need (cite from man page):

git-describe - Show the most recent tag that is reachable from a commit

If your last released version is for example 2.6.9, git describe will give you the following output:

2.6.9-<NUMCOMMITS>-g<CURRENTREV>

If your current branch points directly to 2.6.9, NUMCOMMITS and CURRENTREV will not be printed and the command only yields 2.6.9.

However, if you did some commits since 2.6.9 (e.g. 3), NUMCOMMITS will be 3 and CURRENTREV will be the 7 chars of the abbreviated last commit hash (e.g. 2597536):

2.6.9-3-g2597536

Same could be achieved for unannotated tags using the --tags switch:

git describe --tags 
eckes
  • 64,417
  • 29
  • 168
  • 201
1

The OP precises in the comments that "release version" isn't about having binaries (deliveries) in the repo, but getting the versions which are used to produced delivery.

git tag alone is not well suite, because the order isn't always pertinent.

However, as i explained in "How to sort git tags?", this would give the right order (with git 2.0+)

git tag -l --sort=refname "v*"
# or
git tag -l --sort=version:refname "v*"

v17
v16
...
v9
...
v1
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I would only add that it's project-specific, and while it seems his project isn't using the ["successful git branching model"](http://nvie.com/posts/a-successful-git-branching-model/) that some number of projects use, there might very well be some branch that has all the release-tagged commits in its first-parent history. – jthill Nov 09 '14 at 21:28
  • @jthill I agree: Git itself doesn't impose anything. This is more about the convention and worflow you want to follow for your project. – VonC Nov 09 '14 at 21:30
  • Perhaps, I asked a wrong question. To illustrate, I will use kmod.git package [link](git://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git). After cloning the repo, I did a *git tag* and it dumps tag list (**v1 v10 v11 v12 v13 v14 v15 v16 v17 v2 v3 v4 v5 v6 v7 v8 v9**). What I would like to do is to be able to grab the latest tag, i.e. v17, from the list. This way, I can write a Makefile recipe to clone or checkout the package source based on the latest tag. I hope that clears up some misunderstanding. – Mazilo Nov 10 '14 at 04:22
  • @user3767809 ok, I have entirely rewritten the answer. – VonC Nov 10 '14 at 08:45
  • Thank you for the update. Unfortunately, your suggestion requires a git v2.0+. This may create some problem because not everyone is currently using git v2.0+, unfortunately. OTOH, you also mentioned about 'git tag'. When I took a look at 'git tag', I can use 'sort + tail' utilities to perform a sort and get the latest version as I want, i.e. *git tag -l | sort --sort=version | tail -1*. However, I don't know if this is the correct way. – Mazilo Nov 10 '14 at 12:48
  • @user3767809 I agree but updating git is easy, so this shouldn't be an issue (unless you are using Git on Windows, in which case, this is problematic) Your sort+tail version could then work just fine. – VonC Nov 10 '14 at 12:54
  • Yes and that will do with additional gnu utilities, i.e. git tag | sort -V + tail -1. – Mazilo Nov 11 '14 at 12:54