I read through a bunch of questions asking about simple source code control tools and Git seemed like a reasonable choice. I have it up and running, and it works well so far. One aspect that I like about CVS is the automatic incrementation of a version number.
I understand that this makes less sense in a distributed repository, but as a developer I want/need something like this. Let me explain why:
I use Emacs. Periodically I go through and look for new versions of the Lisp source files for third-party packages. Say I've got a file, foo.el, which, according to the header, is version 1.3; if I look up the latest version and see it's 1.143 or 2.6 or whatever, I know I'm pretty far behind.
If instead I see a couple of 40-character hashes, I won't know which is later or get any idea of how much later it is. I would absolutely hate it if I had to manually check ChangeLogs just to get an idea of how out of date I am.
As a developer, I want to extend this courtesy, as I see it, to the people that use my output (and maybe I'm kidding myself that anyone is, but let's leave that aside for a moment). I don't want to have to remember to increment the damn number myself every time, or a timestamp or something like that. That's a real PITA, and I know that from experience.
So what alternatives do I have? If I can't get an $Id:$ equivalent, how else can I provide what I'm looking for?
I should mention that my expectation is that the end user will NOT have Git installed and even if they do, will not have a local repository (indeed, I expect not to make it available that way).
To resolve this issue for myself, I created small "hack" as post-commit hook:
In more detail documented in this post on my blog.
If I understand correctly, essentially, you want to know how many commits have happened on a given file since you last updated.
First get the changes in the remote origin, but don't merge them into your
master
branch:Then get a log of the changes that have happened on a given file between your
master
branch and the remoteorigin/master
.This gives you the log messages of all the commits that have happened in the remote repository since you last merged
origin/master
into yourmaster
.If you just want a count of the changes, pipe it to
wc
. Say, like this:By now there is support for $Id:$ in Git. To enable it for file README you would put "README ident" into .gitattributes. Wildcards on file names are supported. See man gitattributes for details.
I agree with those who think that token replacement belongs to build tools rather than to version control tools.
You should have some automated release tool to set the version IDs in your sources at the time the release is being tagged.
I also came from SCCS, RCS, and CVS (
%W% %G% %U%
).I had a similar challenge. I wanted to know what version a piece of code was on any system running it. The system may or may not be connected to any network. The system may or may not have Git installed. The system may or may not have the GitHub repository installed on it.
I wanted the same solution for several types of code (.sh, .go, .yml, .xml, etc). I wanted any person without knowledge of Git or GitHub to be able to answer the question "What version are you running?"
So, I wrote what I call a wrapper around a few Git commands. I use it to mark a file with a version number and some information. It solves my challenge. It may help you.
https://github.com/BradleyA/markit
Since you use Emacs, you might be lucky :)
I've came across this question by coincidence, and also by coincidence I've came by Lively few days ago, an Emacs package which allows having lively pieces of Emacs Lisp in your document. I've not tried it to be honest, but it came to my mind when reading this.