title: How to manage the version number in Git?
body: <p>Let's imagine the <a href="http://xkcd.com/1692/" rel="nofollow noreferrer">blerp</a> command line tool maintained on <a href="/questions/tagged/git" class="post-tag" title="show questions tagged &#39;git&#39;" rel="tag" aria-labelledby="git-container">git</a>. This tool has the (hidden) <code>--version</code> option which returns its <a href="https://en.wikipedia.org/wiki/Software_versioning" rel="nofollow noreferrer">version</a> (let's say <code>0.1.2</code>) and another <code>--commit</code> which returns the commit number from which it was built.</p>
  <p>Both the version and the commit number are hard-coded on the code base.</p>
  <p>Now I make a bugfix then commit and rebuild my program. I will still see <code>0.1.2</code> although this new version differs from the original <code>0.1.2</code>. Only the commit will tell me that it is not the same <code>0.1.2</code>. Is that bugfix worth a different version number?</p>
  <p>One solution is that each time I make a commit, I increase the hard-coded version number (which implies to always modify a minimum of 2 files for each commit). This is a binding solution and it does not work when the developers are working on different active branches. If Bob works on feature <code>foo</code> from the version <code>0.1.2</code> and Alice works on feature <code>bar</code> from the same version, how do they increase their version number? Bob can use the odd and Alice the even. What if Eve works on a third feature?</p>
  <p>Another solution can be to use Git tags to automatically generate the version number. A script can find the closest tag starting with <code>v</code> such as <code>v0.1.2</code> and use the tag name as the version number plus the first n digits of the current commit (<code>v0.1.2 (build 4acd21)</code>). This works well if the working directory is clean. One can imagine to add a <code>*</code> before the build number to indicate the working directory is not clean. The main problem with this solution is if somebody exports the sources, it won't be able to build <em>blerp</em>.</p>
  <p>What possible alternative can solve this issue?</p>