I need a simple way to get the revision of file using cvs. I can get it using the CVS/Entries
file. It is not safe and I think there must be another way. cvs log
prints too much than I need. How can I get only the revision number of some file using cvs commands.
问题:
回答1:
cvs log -h
shows just the header information. To get just the version, it's easy enough to filter that through sed, awk, or Perl.
This gives you the version in the repository. If you want the version of the checked-out file, you can use ident
(part of RCS) -- but only if you've included the proper keywords in the file. (This doesn't work well for binaries.)
For example, if you add something like the following to your file before checking it in:
# $Id:$
# $Source:$
then ident foo.txt
will print something like this:
foo.txt:
$Id: foo.txt,v 1.3 2011/10/17 22:49:45 kst Exp $
$Source: /path/to/repo/sandbox/foo.txt,v $
There are a number of other keywords you can use. See the Keyword substitution section of the CVS manual for details.
This can go wrong in various ways; for example, if you edit the file after checking it out, the expanded keywords won't necessarily reflect anything meaningful. You can use cvs diff
to determine whether a file has been modified after checkout.
As I mentioned, if you try to do this with a binary file, it can corrupt the file (which is why if you tell CVS that a file is binary, it won't do keyword substitution).
The ident
command is part of RCS, not CVS, so you'll have to install RCS on your system if it's not already there. (It would have made sense to have a cvs ident
command; I'm not sure why it's not there.)
More "modern" source control systems tend not to provide this facility.