2

I am in the process of migrating my VCS from Subversion to Git. When I used Subversion, I used to use the Subversion revision number as the last component of my assembly versions. In TeamCity, I used %build.vcs.number% as part of the build number format and I used the 'AssemblyInfo Patcher' (or sometimes MSBuild Community Tasks) to update my AssemblyVersion attributes with the version number prior to compiling. This all worked rather well and made it easy to track any given assembly back to the exact source revision.

Unfortunately in Git, there are no longer revision numbers. Instead we have the long hexadecimal hash code which can't be used within an AssemblyVersion. This is the one thing so far that I lament about changing to Git.

Is there a way to retrieve a simple numeric version identifier from Git that I could use in my build configurations as described above?

alroc
  • 27,574
  • 6
  • 51
  • 97
Tim Long
  • 13,508
  • 19
  • 79
  • 147
  • 1
    Possible duplicate of http://stackoverflow.com/questions/4120001/what-is-the-git-equivalent-for-revision-number and http://stackoverflow.com/questions/677436/how-to-get-the-git-commit-count – Ed Plese Apr 18 '13 at 23:21
  • Thanks for the duplicate links - they didn't come up in my search. – Tim Long Apr 18 '13 at 23:57

1 Answers1

1

git describe is the closest I have found to a revision number. It gives you

  • name of last tag
  • number of commits since that tag
  • commit SHA
$ git clone git://github.com/antirez/redis

$ cd redis

$ git describe
with-deprecated-diskstore-2853-g5a526c2

or if you just want the number

$ git describe | awk '$0=$--NF' FS=-
2853
Zombo
  • 1
  • 62
  • 391
  • 407
  • I've come to the conclusion that this isn't going to be viable with Git, so I've given up on using the Major.Minor.Build.Revision format. I'll probably use SemVer instead, with the 4th position being the auto-incrementing build number. I plan to put the Git revision into one of the assembly attributed, probably the [AssemblyConfiguration] attribute, but I'm waiting for TeamCity 8 before I do that. – Tim Long May 28 '13 at 00:21