# Does CVS has a easy way to compare file with its previous version?

10 messages from 2009-06-30 to 2009-07-07. Participants: dtletmn, Andreas Ericsson, Jakub Narebski, Paolo Bonzini, Linus Torvalds, Eric Raible.
Thread: https://gitlist.dev/t/19979

## dtletmn, 2009-06-30 07:41

Subject: Does CVS has a easy way to compare file with its previous version?
Message-ID: <1e56aa11-735a-47f7-a273-5b6bf611f528@n11g2000yqb.googlegroups.com>
URL: https://gitlist.dev/e/1e56aa11-735a-47f7-a273-5b6bf611f528%40n11g2000yqb.googlegroups.com

```
Hi,All,

     I am wondering if cvs has an easy way to compare a file with its
previous version.

     In clearcase,I can use  :
       cleartool diff -pred file.cc

     how can I acheive it in CVS?
     any help would be highly appreciated!

     Thanks,
     dt

```

## Andreas Ericsson, 2009-06-30 11:32

Subject: Re: Does CVS has a easy way to compare file with its previous version?
Message-ID: <4A49F7BF.9070209@op5.se>
URL: https://gitlist.dev/e/4A49F7BF.9070209%40op5.se
In-Reply-To: <1e56aa11-735a-47f7-a273-5b6bf611f528@n11g2000yqb.googlegroups.com>

```
dtletmn wrote:
> Hi,All,
> 
>      I am wondering if cvs has an easy way to compare a file with its
> previous version.
> 
>      In clearcase,I can use  :
>        cleartool diff -pred file.cc
> 
>      how can I acheive it in CVS?
>      any help would be highly appreciated!
> 

Why you're posting this to the git mailing list I have no idea, but
assuming you mean "how do I compare a file in git with the content
it had in the previous snapshot?", the answer would be:

  git diff HEAD^ -- path/to/file

This command works equally well on directories or multiple paths.
Note that if there are no differences, the program will just exit
silently.

If you want to see the differences compared to the *latest* commit,
you'd do

  git diff HEAD -- path/to/file

If you want to see the differences compared to what you've staged
for committing next, you'd do

  git diff -- path/to/file

If you want to see the differences between what you've already
staged and the latest snapshot, you'd do

  git diff --staged -- path/to/file

-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231

Considering the successes of the wars on alcohol, poverty, drugs and
terror, I think we should give some serious thought to declaring war
on peace.

```

## Jakub Narebski, 2009-06-30 12:36

Subject: Re: Does CVS has a easy way to compare file with its previous version?
Message-ID: <m3hbxxx5jk.fsf@localhost.localdomain>
URL: https://gitlist.dev/e/m3hbxxx5jk.fsf%40localhost.localdomain
In-Reply-To: <1e56aa11-735a-47f7-a273-5b6bf611f528@n11g2000yqb.googlegroups.com>

```
dtletmn <dtletmedn@gmail.com> writes:

> Hi,All,
> 
>      I am wondering if cvs has an easy way to compare a file with its
> previous version.
> 
>      In clearcase,I can use  :
>        cleartool diff -pred file.cc
> 
>      how can I acheive it in CVS?
>      any help would be highly appreciated!

In CVS or in Git?

In CVS: "cvs diff -r <previous revision> <file>".
In Git: "git diff HEAD^ -- <file>".

Both assume that you want to compare with version from previous
commit.
-- 
Jakub Narebski
Poland
ShadeHawk on #git

```

## Paolo Bonzini, 2009-06-30 23:28

Subject: Re: Does CVS has a easy way to compare file with its previous version?
Message-ID: <4A4A9FA5.7000009@gnu.org>
URL: https://gitlist.dev/e/4A4A9FA5.7000009%40gnu.org
In-Reply-To: <m3hbxxx5jk.fsf@localhost.localdomain>

```
On 06/30/2009 02:36 PM, Jakub Narebski wrote:
> dtletmn<dtletmedn@gmail.com>  writes:
>
>> Hi,All,
>>
>>       I am wondering if cvs has an easy way to compare a file with its
>> previous version.
>>
>>       In clearcase,I can use  :
>>         cleartool diff -pred file.cc
>>
>>       how can I acheive it in CVS?
>>       any help would be highly appreciated!
>
> In CVS or in Git?
>
> In CVS: "cvs diff -r<previous revision>  <file>".
> In Git: "git diff HEAD^ --<file>".

I think he wants something more like

git diff `git log -2 --pretty=format:%h` <file> -- <file>

In CVS it should not be hard, but I definitely have no idea.

Paolo

```

## dtletmn, 2009-07-01 00:29

Subject: Re: Does CVS has a easy way to compare file with its previous version?
Message-ID: <e4802579-a779-4f4a-99e2-1761e3e5312f@h2g2000yqg.googlegroups.com>
URL: https://gitlist.dev/e/e4802579-a779-4f4a-99e2-1761e3e5312f%40h2g2000yqg.googlegroups.com
In-Reply-To: <1e56aa11-735a-47f7-a273-5b6bf611f528@n11g2000yqb.googlegroups.com>

```

Thanks all very much for the help!!

```

## Linus Torvalds, 2009-07-01 01:18

Subject: Re: Does CVS has a easy way to compare file with its previous version?
Message-ID: <alpine.LFD.2.01.0906301813480.3605@localhost.localdomain>
URL: https://gitlist.dev/e/alpine.LFD.2.01.0906301813480.3605%40localhost.localdomain
In-Reply-To: <4A4A9FA5.7000009@gnu.org>

```


On Wed, 1 Jul 2009, Paolo Bonzini wrote:
> 
> I think he wants something more like
> 
> git diff `git log -2 --pretty=format:%h` <file> -- <file>

That's a rather difficult way of saying

	git log --no-merges -p -1 <filename>

which seems much simpler. Sure, you'll get the commit message too, but 
that just sounds like gravy to me (you can use "--pretty=oneline" or 
something to make it denser).

			Linus

```

## Eric Raible, 2009-07-02 18:04

Subject: Re: Does CVS has a easy way to compare file with its previous version?
Message-ID: <loom.20090702T174843-784@post.gmane.org>
URL: https://gitlist.dev/e/loom.20090702T174843-784%40post.gmane.org
In-Reply-To: <alpine.LFD.2.01.0906301813480.3605@localhost.localdomain>

```
Linus Torvalds <torvalds <at> linux-foundation.org> writes:

> On Wed, 1 Jul 2009, Paolo Bonzini wrote:
> > 
> > I think he wants something more like
> > 
> > git diff `git log -2 --pretty=format:%h` <file> -- <file>
> 
> That's a rather difficult way of saying
> 
> 	git log --no-merges -p -1 <filename>
> 
> which seems much simpler. Sure, you'll get the commit message too, but 
> that just sounds like gravy to me (you can use "--pretty=oneline" or 
> something to make it denser).
> 
> 			Linus

Isn't the first one incorrect because  <file> needs to be inside the backticks?
git diff `git log -2 --pretty=format:%h <file>` -- <file>

And isn't the replacement incorrect also (the diffs are backwards)?
git log --no-merges -p -R -1 <file>

- Eric

```

## Paolo Bonzini, 2009-07-03 06:39

Subject: Re: Does CVS has a easy way to compare file with its previous version?
Message-ID: <4A4DA7A5.7020303@gnu.org>
URL: https://gitlist.dev/e/4A4DA7A5.7020303%40gnu.org
In-Reply-To: <loom.20090702T174843-784@post.gmane.org>

```
On 07/02/2009 08:04 PM, Eric Raible wrote:
> Isn't the first one incorrect because<file>  needs to be inside the backticks?
> git diff `git log -2 --pretty=format:%h<file>` --<file>
>
> And isn't the replacement incorrect also (the diffs are backwards)?
> git log --no-merges -p -R -1<file>

Yes and no.

Paolo

```

## Eric Raible, 2009-07-06 23:39

Subject: Re: Does CVS has a easy way to compare file with its previous version?
Message-ID: <279b37b20907061639o6d6c72e7qf7bbc2459c7fc77e@mail.gmail.com>
URL: https://gitlist.dev/e/279b37b20907061639o6d6c72e7qf7bbc2459c7fc77e%40mail.gmail.com
In-Reply-To: <4A4DA7A5.7020303@gnu.org>

```
On Thu, Jul 2, 2009 at 11:39 PM, Paolo Bonzini<bonzini@gnu.org> wrote:
> On 07/02/2009 08:04 PM, Eric Raible wrote:
>>
>> Isn't the first one incorrect because<file>  needs to be inside the
>> backticks?
>> git diff `git log -2 --pretty=format:%h<file>` --<file>
>>
>> And isn't the replacement incorrect also (the diffs are backwards)?
>> git log --no-merges -p -R -1<file>
>
> Yes and no.
>
> Paolo
>

Are you sure that you didn't mean yes and yes?

As the transcript shows the git-diff form produces a
backwards diff.  Thus to get the same output git-log
needs the -R:

$ git init
$ perl -e 'for (0..10) { print "$_\n" }' > file
$ git add file
$ git commit -minitial
[master (root-commit) 2d451ec] initial
 1 files changed, 11 insertions(+), 0 deletions(-)
 create mode 100644 file
$ sed -e 's/4/four/' < file > file1
$ mv file1 file
$ git commit -a -m'updated'
[master d49613a] updated
 1 files changed, 1 insertions(+), 1 deletions(-)
$ git diff `git log -2 --pretty=format:%h file` -- file
diff --git a/file b/file
index b29b605..b033488 100644
--- a/file
+++ b/file
@@ -2,7 +2,7 @@
 1
 2
 3
-four
+4
 5
 6
 7

$ git log --no-merges -p -1 file
commit d49613a1d16c9ece551f9a52f56f16a3dae8bebc
Author: Eric Raible <raible@nextest.com>
Date:   Mon Jul 6 16:25:29 2009 -0700

    updated

diff --git a/file b/file
index b033488..b29b605 100644
--- a/file
+++ b/file
@@ -2,7 +2,7 @@
 1
 2
 3
-4
+four
 5
 6
 7

$ git log --no-merges -p -R -1 file
commit d49613a1d16c9ece551f9a52f56f16a3dae8bebc
Author: Eric Raible <raible@nextest.com>
Date:   Mon Jul 6 16:25:29 2009 -0700

    updated

diff --git b/file a/file
index b29b605..b033488 100644
--- b/file
+++ a/file
@@ -2,7 +2,7 @@
 1
 2
 3
-four
+4
 5
 6
 7

```

## Paolo Bonzini, 2009-07-07 19:57

Subject: Re: Does CVS has a easy way to compare file with its previous version?
Message-ID: <4A53A8BA.6060505@gmail.com>
URL: https://gitlist.dev/e/4A53A8BA.6060505%40gmail.com
In-Reply-To: <279b37b20907061639o6d6c72e7qf7bbc2459c7fc77e@mail.gmail.com>

```
On 07/07/2009 01:39 AM, Eric Raible wrote:
> On Thu, Jul 2, 2009 at 11:39 PM, Paolo Bonzini<bonzini@gnu.org>  wrote:
>> On 07/02/2009 08:04 PM, Eric Raible wrote:
>>> Isn't the first one incorrect because<file>    needs to be inside the
>>> backticks?
>>> git diff `git log -2 --pretty=format:%h<file>` --<file>
>>>
>>> And isn't the replacement incorrect also (the diffs are backwards)?
>>> git log --no-merges -p -R -1<file>
>> Yes and no.
>>
>> Paolo
>>
>
> Are you sure that you didn't mean yes and yes?

I'm sure; I'm not sure I was right (though I did retest at the time, and 
I was convinced that Linus's alternative worked).

Paolo

```
