Auto Versioning with Git in Visual C++

c++, git, visual-c++

Solution

I've eventually found a really useful batch file which actually does way more than I need :

https://github.com/Thell/git-vs-versioninfo-gen

It basically does a very similar job to SubWCRev and generates a header file that I can include in my VS project to set all the version strings. After a bit of hacking around with the script I've got it to do exactly what I wanted.

There's a C# version here too :

https://github.com/jasperboot/git-vs-versioninfo

Problem

I have a C++ project in VS2013. In the past on similar projects I've used SubWCRev with Subversion to auto generate version numbers. I had a template file like this : ``` #define MAJOR_VERSION 2 #define MINOR_VERSION 2 #define MICRO_VERSION 0 #define BUILD_VERSION $WCMODS?$WCREV$+1:$WCREV$$ #define QUOTE_(x) #x #define QUOTE(x) QUOTE_(x) #define BUILD_VERSION_STRING QUOTE(MAJOR_VERSION.MINOR_VERSION.MICRO_VERSION.BUILD_VERSION) ``` Then I ran SubWCRev as a pre-build step to generate the header file which I included in the project to define the version numbers. I'm now using Git and want to do something similar. I know that Git doesn't have an equivalent of revision number but the HEAD SHA would be fine. It doesn't seem like there's an equivalent way to do this with Git and I need to do some scripting which isn't my strong point. Could a Git Guru point me in the right direction to achieve this?

Original source