views:

156

answers:

2

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?

+4  A: 

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?.

VonC
I agree that you should not be injecting version numbers into your source code and then storing it in version control. The version number should be determined at build time - perhaps replacing tokens in your source code or using properties files.
spilth
+3  A: 

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
Zitrax
I never got to tag the original commit. In other words, I was given someone else's old code, updated it to work with the latest version of the compiler, then discovered Git. I have two commits: the original code and my changes. I guess the original would be the master, right? So then, how do I tag the master? (Actually, he's not a master...his code really sucks...LOL.)
PalaDolphin
master is a branch so unless you created a new branch both your commits would be on it.
Zitrax