threads / discuss / 19979

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

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

## tl;dr

10 messages between Jun 30, 2009 and Jul 7, 2009.

replies: 9people: 7as markdown or json

dtletmn· Jun 30, 2009, 07:41 UTC · lore
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· Jun 30, 2009, 11:32 UTC · re: dtletmn · lore

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

dtletmn wrote:
Show 11 quoted lines
> 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· Jun 30, 2009, 12:36 UTC · re: dtletmn · lore

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

dtletmn <dtletmedn@gmail.com> writes:
Show 10 quoted lines
> 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· Jun 30, 2009, 23:28 UTC · re: Jakub Narebski · lore

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

On 06/30/2009 02:36 PM, Jakub Narebski wrote:
Show 17 quoted lines
> 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
Linus Torvalds· Jul 1, 2009, 01:18 UTC · re: Paolo Bonzini · lore

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

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· Jul 2, 2009, 18:04 UTC · re: Linus Torvalds · lore

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

Linus Torvalds <torvalds <at> linux-foundation.org> writes:
Show 15 quoted lines
> 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· Jul 3, 2009, 06:39 UTC · re: Eric Raible · lore

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

On 07/02/2009 08:04 PM, Eric Raible wrote:
Show 5 quoted lines
> 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· Jul 6, 2009, 23:39 UTC · re: Paolo Bonzini · lore

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

On Thu, Jul 2, 2009 at 11:39 PM, Paolo Bonzini<bonzini@gnu.org> wrote:
Show 13 quoted lines
> 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· Jul 7, 2009, 19:57 UTC · re: Eric Raible · lore

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

On 07/07/2009 01:39 AM, Eric Raible wrote:
Show 14 quoted lines
> 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

← back to recent threads