1

How do I write a script which will create a source file containing the version number? I would like the build number (4th number in the version quadruple) to be autoincremented for each commit.

I found some examples on how to use bash commands to do it:

INCREMENT=`git-rev-list $BRANCH..HEAD | wc -l | awk '{print $1}'`

but I am using Windows and I don't have a clue how to run that as a script (or a Windows batch file).

I used to work with SVN, and it worked nicely from the command prompt, so I just used it in a batch file, but I don't know how to execute git-rev-list without starting git bash.

2
  • from where will the script be ran?
    – CharlesB
    Sep 3, 2012 at 12:38
  • @CharlesB it will be included in the build process, this means a build script or something. When I push the project, I want the version number to be incremented.
    – Lou
    Sep 4, 2012 at 7:51

2 Answers 2

3

As the git is distributed VCS it is impossible to keep global incremented number, there is no place for it. So, the right thing to do is to use the <commit sha1> (or its fragment) as a build number. You could use git describe to generate nice version names automatically, including an incremented number.

Another good option is to have a build server (e.g. Jenkins or similar) which has built-in version numbering.

If you want use the hackish approach, you could use git installation, e.g. msysgit, it has all commands such as ws or awk. Not sure then why your doesn't work, maybe you don't have Git\bin folder in your PATH.

5
  • Thanks a lot. Actually, is it possible to get an incrementing number for each push to the remote repo? I know I wrote commit in my question, but push actually makes more sense with versioning. The thing is, with SVN this number would automatically increase and my Setup would always know if a client has an older version installed. With Git, it seems I will have to create these tags manually?
    – Lou
    Sep 4, 2012 at 7:56
  • And the thing is, I have Git\bin in my PATH. If I enter git in my command prompt, it works, but git-rev-list doesn't. Is that even an actual command?
    – Lou
    Sep 4, 2012 at 8:03
  • You could have several remote repos. All repos are equal (but some repos are more equal than others). The git describe names version in relation to a tag. So, if you have a tag named v1.2.3 and 15 commits after it, the name will be v1.2.3-15-g6c28c25. Just read the documentation.
    – kan
    Sep 4, 2012 at 8:23
  • 2
    @Dilbert use git rev-list instead of git-rev-list
    – kan
    Sep 4, 2012 at 8:24
  • Oh, crap, that's pretty obvious. Thanks.
    – Lou
    Sep 4, 2012 at 8:53
2

AssemblyInfomationalVersionAttribute may hold any string, including the hash or shorthash or output of git describe

4
  • Thanks, but what I wanted is to have an incrementing version number whenever I push my source, so that Windows Installer can know if user has a newer application version already (and it will simplify automatic updates). Otherwise I need to tag the release manually, which I didn't have to do with SVN.
    – Lou
    Sep 4, 2012 at 7:52
  • To automatically generate the last digit, parse the output of git describe to extract the relative number
    – linquize
    Sep 4, 2012 at 7:54
  • You meant, parse the output of git describe? Right now it only returns heads/master. Do I need to create a tag for this to work?
    – Lou
    Sep 4, 2012 at 8:05
  • At least tag one version as the baseline, such as v1.0. After that, you can git describe [--tags]
    – linquize
    Sep 4, 2012 at 8:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.