PalaDolphin
PalaDolphin

Reputation: 177

Does Git track Versions?

I am a Git newbee with UNIX SCCS and Microsoft Visual SourceSafe experience.

In SCCS, each file has a version (I%), which is made of Release (%R), Level (L%), Branch (%B), and Sequence (S%). %I is equal to R%.%L.B%.%S, okay? These are referred to as ID Keywords.

The purpose is you insert these ID Keywords in the source code before checking them in, then when you check them out for read-only (not to change), It’ll convert them to their version number. For example:

printf(“Version s\n”, “%I“);

...will become,

printf(“Version %s\n”, “1.4.6.2”);

Which will print,

Version 1.4.6.2

SCCS keeps track of versions on a file-by-file basis and increments them each time they’re checked in.

Is there anything close to that in Git?

Upvotes: 5

Views: 1402

Answers (2)

VonC
VonC

Reputation: 1324757

As discussed in the SO question "To put the prefix ? to codes by Git/Svn", Git has no RCS keyword expansion.

The closest Git command would be git describe, to have some kind of commit reference.

But it is generally not a good idea mixing meta-data (i.e. data "version id" about data "the file") with data (the files).
If you really need this kind of information, a separate special file listing your other regular file, with their associated version id is more practical.

Even ClearCase, which has similar notions than SCS in term of per-file branch and sequence, does not have embedded version numbers: See Embedded Version Numbers - Good or Evil?.

Upvotes: 5

Zitrax
Zitrax

Reputation: 20265

You can generate unique tag names using git-describe.

The command finds the most recent tag that is reachable from a commit. If the tag points to the commit, then only the tag is shown. Otherwise, it suffixes the tag name with the number of additional commits on top of the tagged object and the abbreviated object name of the most recent commit.

Example of how to determine software revision number with ‘git describe’ (from here):

01  git commit -m'Commit One.'
02  git tag -a -m'Tag One.' 1.2.3
03  git describe    # => 1.2.3
04  git commit -m'Commit Two.'
05  git describe    # => 1.2.3-1-gaac161d
06  git commit -m'Commit Three.'
07  git describe    # => 1.2.3-2-g462715d
08  git tag -a -m'Tag Two.' 2.0.0
09  git describe    # => 2.0.0

Upvotes: 4

Related Questions