Search code examples
diffcvs

Getting diff between top two revisions of a file in CVS


Is there way to create the diff of a file b/w its top two revisions in the CVS repo? I doesn't care about the revision numbers and my local checked-out file. All I need is, the diff b/w the last commit and the last before commit.


Solution

  • You can use

    cvs diff -r FIRSTREVISION -r SECONDREVISION filename
    

    to compare two revisions.

    It may be possible to do the comparison you require directly, but we can also automate it by processing the results of cvs log filename. So, for example, you get the latest revision number with

    cvs log filename | grep ^revision | head -n 1 | cut -c 10-
    

    and the previous revision with

    cvs log filename | grep ^revision | head -n 2 | tail -n 1 | cut -c 10-
    

    You want to merge these together, so create a BASH script file (say called lastdiff.sh) that contains:

    cvs diff -r $(cvs log $1 | grep ^revision | head -n 2 | tail -n 1 | cut -c 10-) -r $(cvs log $1 | grep ^revision | head -n 1 | cut -c 10-) $1
    

    and then you'll be able to get your diff by executing it with the filename as a parameter, e.g. ./lastdiff.sh filename.