Section 14.3. Using Subversion: A Quick Tour


14.3. Using Subversion: A Quick Tour

This section provides a very quick tour of using Subversion for version control. We start with the initial version of a project for importing into Subversion:

     $ find /tmp/hello -print                    Show directory layout     /tmp/hello     /tmp/hello/branches                        Directory for branch development     /tmp/hello/tags                            Directory for tagged releases     /tmp/hello/trunk     /tmp/hello/trunk/hello.c                   Mainline development is done on the trunk     /tmp/hello/trunk/Makefile     /tmp/hello/trunk/README 

The next steps are to create the repository and then to import the project into it:

     $ svnadmin create /path/to/svnrepos     $ svn import /tmp/hello file:///path/to/svnrepos -m "initial import"     Adding         /tmp/hello/trunk     Adding         /tmp/hello/trunk/hello.c     Adding         /tmp/hello/trunk/Makefile     Adding         /tmp/hello/trunk/README     Adding         /tmp/hello/branches     Adding         /tmp/hello/tags           Committed revision 1. 

Now that the project exists in Subversion, we check out a working copy into a sandbox underneath our home directory and start making changes:

     $ cd                                             Move to home directory     $ svn checkout file:///path/to/svnrepos hello    Check out working copy     A  hello/trunk     A  hello/trunk/hello.c     A  hello/trunk/README     A  hello/trunk/Makefile     A  hello/branches     A  hello/tags     Checked out revision 1.           $ cd hello/trunk                                 Change to sandbox     $ vi message.c hello.c Makefile                  Make changes     3 files to edit           $ cat message.c                                  Show newly created file     const char message[  ] = "hello, world!";     $ make                                           Compile program and test it     cc    -c -o hello.o hello.c     cc    -c -o message.o message.c     cc -O hello.o message.o -o hello     $ hello      hello, world! 

One of the most common operations is to compare the changed copy with the original. The result is in unified diff format, the equivalent of the regular diff -u command:

     $ svn diff hello.c     Index: hello.c     ===============================================================     ====     --- hello.c     (revision 1)     +++ hello.c     (working copy)     @@ -1,7 +1,9 @@      #include <stdio.h>            +extern const char message[  ];     +      int main(void)      {     -       printf("hello, world!\n");     +       printf("%s\n", message);             return 0;      } 

Now that we're comfortable with the changes, we schedule the new file, message.c, for addition to the repository, and then we actually commit our changes:

     $ svn add message.c                              Schedule message.c for addition     A         message.c     $ svn commit                                     Commit all the changes     Sending        trunk/Makefile     Sending        trunk/hello.c     Adding         trunk/message.c     Transmitting file data ...     Committed revision 2. 

Finally, we can view all our changes relative to the initial revision:

     $ svn diff -r 1     Index: hello.c     ===================================================================     --- hello.c     (revision 1)     +++ hello.c     (working copy)     @@ -1,7 +1,9 @@      #include <stdio.h>            +extern const char message[  ];     +      int main(void)      {     -       printf("hello, world!\n");     +       printf("%s\n", message);             return 0;      }     Index: Makefile     =================================================================     ==     --- Makefile    (revision 1)     +++ Makefile    (working copy)     @@ -1,2 +1,2 @@     -hello: hello.c     -       $(CC) -O $< -o $@     +hello: hello.o message.o     +       $(CC) -O hello.o message.o -o $@     Index: message.c     =================================================================     ==     --- message.c   (revision 0)     +++ message.c   (revision 2)     @@ -0,0 +1 @@     +const char message[  ] = "hello, world!"; 



Linux in a Nutshell
Linux in a Nutshell
ISBN: 0596154488
EAN: 2147483647
Year: 2004
Pages: 147

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net