Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting diff between top two revisions of a file in CVS

Tags:

diff

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.

like image 513
Babu S Avatar asked Jun 27 '11 08:06

Babu S


People also ask

Which command is used to show the difference between two revisions?

The diff command is used to compare different revisions of files. The default action is to compare your working files with the revisions they were based on, and report any differences that are found. If any file names are given, only those files are compared.

How does cvs check diff?

You can call cvs diff with filenames, directories, or module names. If you don't give a filename, the current working directory is the default. Usually, you call cvs diff with at least one -r tag or -D date command option.

How do I view modified files in cvs?

To see the changes that you have made since you checked out your local copy, use the command cvs diff. Keep in mind that cvs diff shows the difference between your working copy and the version it was based on.

How do I view cvs file history?

You can use the history file (see section The history file) to log various CVS actions. To retrieve the information from the history file, use the cvs history command (see section history--Show status of files and users).

How does CVS compare the current version of a file?

If you invoke it with a single -r or -D parameter, CVS compares the current copy in the working directory with the version in the repository. For example, if you check out revision 1.6 of Makefile, edit the file, then run cvs diff -r 1.6 Makefile, diff displays the changes you made to Makefile since you checked it out.

Is there a way to get the two latest revisions in CVS?

If for whatever reason you're still using cvs, you might find this refinement useful: 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. Show activity on this post.

How to compare two revisions of the same file?

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

What is CVS diff and how do I use it?

This usually happens when several developers are working on the same file and you need to know which changes were made to a file since you last worked on it. The cvs diff command compares two revisions of a file and displays the differences.


1 Answers

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.

like image 96
borrible Avatar answered Sep 27 '22 19:09

borrible