info-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cvs diff -N


From: Greg A. Woods
Subject: Re: cvs diff -N
Date: Sat, 16 Mar 2002 15:45:42 -0500 (EST)

[ On Saturday, March 16, 2002 at 12:22:11 (+0100), Jean-Pierre Bergamin wrote: ]
> Subject: cvs diff -N
>
> Maybe I understand the -N option totally wrong, but...
> 
> I have a new file in my working directory, but
> cvs diff -u -N
> only shows "? newfile.c", but not the content. Isn't the -N parameter
> supposed to output the content of new files?

Yes, I think you do understand the meaning and use of "cvs diff -N".
However the real solution to your problem is to understand the status of
a file as CVS perceives it.  A file displayed as "? newfile.c" is not
``new'' from CVS's point of view, but rather ``unknown'' (which is
exactly what the question mark means in this context).

        $ echo hi there > newfile.c
        $ cvs diff newfile.c
        cvs diff: I know nothing about newfile.c
        $ cvs diff -N newfile.c
        cvs diff: I know nothing about newfile.c
        $ cvs status newfile.c
        cvs status: use `cvs add' to create an entry for newfile.c
        ===================================================================
        File: newfile.c        Status: Unknown
        
           Working revision:    No entry for newfile.c
           Repository revision: No revision control file

        $ 

CVS isn't like plain "diff -r" -- it doesn't assume every unknown file
is important.  First you need to add the file, i.e. tell CVS that it is
supposed to care about it:

        $ cvs add newfile.c
        cvs add: scheduling file `newfile.c' for addition
        cvs add: use 'cvs commit' to add this file permanently
        $ 

Then it will know you want to treat the file as source and if you give
it the "-N" flag it'll show you the newly added file in the format
"patch" would understand as a command to create a new file:

        $ cvs diff -c -N newfile.c 
        Index: newfile.c
        ===================================================================
        RCS file: newfile.c
        diff -N newfile.c
        *** /dev/null   1 Jan 1970 00:00:00 -0000
        --- newfile.c   16 Mar 2002 20:08:54 -0000
        ***************
        *** 0 ****
        --- 1 ----
        + hi there
        $ 

Note that if you also commit the newly added file then you will have to
compare against a release tag (or some alternate branch, etc.)  where
the file did not exist before CVS can do anything special for the "-N"
flag.

        $ cvs commit -m 'new file' newfile.c
        RCS file: /cvs/test/tdoc/newfile.c,v
        done
        Checking in newfile.c;
        /cvs/test/tdoc/newfile.c,v  <--  newfile.c
        initial revision: 1.1
        done
        $ cvs diff -N newfile.c
        $ 

That's of course because now "cvs diff" has nothing to show since
there's nothing new or different to show about the file -- it is ``up to
date'' with respect to the repository.

BTW, personally I put "diff -c -N" right in my ~/.cvsrc as I always want
to see the (context-)diff style presentation of added and removed files.

> How can i achieve to show the new file's content?

Other than adding the file your only option is to view it directly,
eg. with "cat newfile.c", or "diff /dev/null newfile.c", etc.

-- 
                                                                Greg A. Woods

+1 416 218-0098;  <address@hidden>;  <address@hidden>;  <address@hidden>
Planix, Inc. <address@hidden>; VE3TCP; Secrets of the Weird <address@hidden>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]