git - How to create runtime version output that reflects the revision/commit of a SCM? -


some programs print version in form of x.y.z-[git commit/svn id] (e.g. 1.3-9-gddc8d41 returned git describe --tags) development releases. know how done regarding following problems:

in order version program printed @ runtime (e.g. when program invoked --version) needs know @ compile time. 1 commits after testing (which implies compilation). either

  • the version printed @ runtime refers previous commit or
  • for every commit 1 has identical set of files updates version (and there's still mismatch between version printed @ runtime , revision id/commit hash in scm)

one determine revision id or commit hash before commit , write version file. how it's done? if yes, how specifically.

if want include actual scm revision/commit identifier, second way list how done. duplicate file set referred tag (in both git , svn), , has several important properties conventions:

  • the tag functionally identical copy source, though changes allowed support versioning;
  • it have no more commits beyond original creation (which times enforced via hooks or permissions).

this way, code in tag matches last revision copied -- except version information -- , apparent "mismatch" of revision numbers irrelevant.

the svn team this, , here can see example of them tagging 1.8.11 , setting version information in same commit.


Comments