7

Possible Duplicate:
what is the git equivalent for revision number?

I have been using subversion for same time now, and would like to switch to git. Having read the manual I have only one reservation, I use svnversion to get a reference number that is: unique, short, monotonic with respect to time (always increases).

  • It must be unique, so I can use it to reproduce the article.
  • It must be short, so it is readable, can be used in file-names, page footers, version number displays.
  • It must only increase ( monotonic with respect to time ), so any one can compare the age of two articles, without knowing the age (date).

Constraint: If we can get a branch ID than the above requirements only have to be met for articles on the same branch. (Branch ID can be anything that can be compared for identity, “is this the release branch?”.

[The word article is used here to represent a computer program, document or something else that is generated from the content of the revision control system.]

Community
  • 1
  • 1
ctrl-alt-delor
  • 7,506
  • 5
  • 40
  • 52

4 Answers4

8

As fork0 stated there's no such equivalent for non-linear histories, you can anyway execute this to get the number of commits for the current branch:

git log --oneline | wc -l

This is what one of my team mates use for generating a build number to be used in the build scripts.

rgngl
  • 5,353
  • 3
  • 30
  • 34
  • You just got my attention with “non-linear histories”, I just realised that the 3 criteria are [I think] met with svnversion for non-linear histories. But I never relied on this, as comparing are of an article an two separate branches is not useful. If I add a constraint to the question that all articles are on the same branch then is this answer now correct? – ctrl-alt-delor Sep 18 '12 at 10:48
  • Yes, it is. I didn't totally get what you mean by articles but in the way we use it, by keeping our builds only from a specific branch, it does the job for us. – rgngl Sep 18 '12 at 10:50
  • I added a note about what I mean by article, sometimes it is this, sometimes it is that. If it is under revision control, then it is a revision controlled article. – ctrl-alt-delor Sep 18 '12 at 10:55
  • Have just tried it using `git svn` and it comes up with a lower number than svn reports, so is probably ok if only using git. But with svn gives inconsistent result. Would be good if it gives same number. `git log --oneline | wc -l' gives `689`, `svnversion` of same repository gives `699` (git using a local clone of svn repo: used `git svn clone -s $url` to make local clone.) – ctrl-alt-delor Sep 28 '12 at 11:51
3

No, there is no such thing for non-linear history. But you might look at git describe, its output will meet at least the two first criteria.

fork0
  • 3,401
  • 23
  • 23
3

The point of the build number is to simplify a process to get a source code for a given build. You could use git show -s --pretty=format:%h to get a sha1 number which uniquely identifies a version, so that any developer could checkout it in his repository.

However, the sha1 is not incremental number and it is impossible to have in most cases even with other VCSs. If you wish to have it, then it is better to introduce a Continuous Integration system (e.g. Jenkins) which will number builds incrementally and create tags for these numbers. In this case it will grow more moderately, because CI usually doesn't build each commit.

Also, the mentioned git describe does a great job to generate good version names.

kan
  • 28,279
  • 7
  • 71
  • 101
0

Smudge|clean filters will allow you to build any ID, YYYYMMDD-N (where N is commit counter for this date) may be good choice

Community
  • 1
  • 1
Lazy Badger
  • 94,711
  • 9
  • 78
  • 110