Getting diff between top two revisions of a file in CVS
Asked Answered
L

3

15

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.

Linnet answered 27/6, 2011 at 8:5 Comment(0)
P
32

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.

Peraza answered 27/6, 2011 at 16:15 Comment(1)
This is very useful. But is there a way to make this work for code committed to branch. With the above solution I am able to get the diff between 1.1 and 1.2 but I want to take a diff between 1.1 and 1.1.2.1.Swingle
M
1

You can use cvs diff to find out the differences between the local checked out version and the version present on the head.

cvs diff -r ver1 -r ver2 <FILE-NAME> 
Messer answered 8/7, 2011 at 7:0 Comment(0)
F
1

I had hoped there was an obvious cvs option I was missing, but borrible's scripted solution seems to be it. If for whatever reason you're still using cvs, you might find this refinement useful:

cvs diff $(cvs log $FILE |
grep "^revision" |
sed "s/^revision/-r/
2q") $FILE

This uses sed to both grab the two latest revisions from a single invocation of "cvs log" and create the -r options directly from that output.

Fieldfare answered 16/8, 2017 at 17:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.