ONLamp.com
oreilly.comSafari Books Online.Conferences.

advertisement


The Top Ten Subversion Tips for CVS Users
Pages: 1, 2

6. Log, log, log your log

Subversion's log command is so much more powerful than CVS log that it merits a mention.

Part of the reason Subversion's log command gives more useful and compact data is that its output is based on an atomic Subversion commit rather than a collection of files that may or may not be part of the same commit. (Keep in mind that CVS has no actual concept of a commit grouping.) So Subversion is able to show you a much more concise view of your repository's log data.

For example:


  $ svn log
  ------------------------------------------------------------------------
  r3 | sally | Mon, 15 Jul 2002 18:03:46 -0500 | 1 line

  Added include lines and corrected # of cheese slices.
  ------------------------------------------------------------------------
  r2 | harry | Mon, 15 Jul 2002 17:47:57 -0500 | 1 line

  Outline sandwich fixins.
  ------------------------------------------------------------------------
  r1 | sally | Mon, 15 Jul 2002 17:40:08 -0500 | 1 line

  Initial import
  ------------------------------------------------------------------------

Each log entry shows you the revision number of the entry, the author, the date, the number of lines in the log entry (to aid in parsing svn log's output), and then the log message itself. If you wish to see the paths that changed in your log output, pass the --verbose flag:


  $ svn log --verbose
  ------------------------------------------------------------------------
  r3 | sally | Mon, 15 Jul 2002 18:03:46 -0500 | 1 line
  Changed paths:
     M /trunk/sandwich.txt

  Added include lines and corrected # of cheese slices.
  ------------------------------------------------------------------------
  r2 | harry | Mon, 15 Jul 2002 17:47:57 -0500 | 1 line
  Changed paths:
     M /trunk/sandwich.txt

  Outline sandwich fixins.
  ------------------------------------------------------------------------
  r1 | sally | Mon, 15 Jul 2002 17:40:08 -0500 | 1 line
  Changed paths:
     A /trunk/sandwich.txt

  Initial import
  ------------------------------------------------------------------------

In the above examples, you might have noticed that we're not passing any specific files or directories (called targets) to the log command. If you run svn log without specifying any targets, Subversion assumes that you're referring to your current working directory. Subversion then uses a starting revision of 1, and the working revision of your current working directory as the ending revision. (You can find out what this working revision is by using svn status -v, as we mentioned earlier.)

And now on to a small gotcha: If you commit a change to a file and immediately run svn log, you won't see the log message for your most recent commit. This is because the "working revision" of your working directory has not been updated (committing a file does not automatically update your working directory or any other files). If you run svn update and then svn log, you'll see the "missing" log message.

See http://svnbook.red-bean.com/svnbook/ch03s06.html#svn-ch-3-sect-5.1 and http://svnbook.red-bean.com/svnbook/re15.html for more information on using svn log.

7. Quickly undo a mistaken commit

Suppose you have a working copy of /trunk and discover that the change you made in revision 303, which changed oyster.c, is completely wrong--it never should have been committed. You can use svn merge to "undo" the change in your working copy*, and then commit the local modification to the repository. All you need to do is specify a reverse difference using svn merge:


  $ svn merge -r 303:302 http://svn.example.com/repos/calc/trunk
  U  oyster.c

Use svn diff to verify that the change is correct, and then commit that to the repository.

For more information, see Undoing Changes.

* That is, restore the latest revision of your repository to its previous state; Subversion will still have the "bad" commit in the repository. Being a version control system, Subversion's job is to remember everything you've ever committed to it.

8. Resurrect deleted items

If you delete a file from your Subversion repository and wish to "resurrect" it into the latest revision of your repository, the easiest way is to svn copy it from a revision before it was deleted into your working copy. Use svn log -v to find the revision where the file was deleted, and then do your copy:


 $ svn copy --revision 807 \
              http://svn.red-bean.com/repos/trunk/perch.c ./perch.c

For more details, see Resurrecting deleted items.

9. Switch to a branch without checking out a new working copy

In CVS, if you have a working copy for your project and are ready to begin work on a branch, you would pass the branch name as the revision to which you wished to update. Because Subversion treats tags and branches as regular paths in the repository, you can't just svn update your working copy to the branch name in question. Enter the svn switch command.

svn switch updates your working copy to mirror a new tree in the repository--say, a branch tree instead of the trunk tree. This is the Subversion way to move a working copy to a new branch.


  $ svn switch http://svn.red-bean.com/repos/branches/vendors-with-fix .
  U  myproj/foo.txt
  U  myproj/bar.txt
  U  myproj/baz.c
  U  myproj/qux.c
  Updated to revision 31.

For more details, see Switching a working copy.

10. Browse or even mount your repository

If your Subversion repository is being served up through the Apache HTTP Server (that is, you access it via a URL beginning with http), Subversion gives you a couple of extremely convenient freebies:

First, you can point any web browser to your Subversion repository and navigate your way through the latest revision of your repository.

Second, if you're using an operating system that knows how to talk to DAV shares, you can mount your Subversion repository (read-only) on your desktop:

While this is a convenient way to see the contents of your repository, it's also very useful for sharing files with non-Subversion users.

Copyright © 2004 Brian W. Fitzpatrick, Ben Collins-Sussman, C. Michael Pilato. This article is distributed under the Creative Commons Attribution License (v 2.0).


O'Reilly Media, Inc., recently released (June 2004) Version Control with Subversion.


Return to ONLamp.com



Sponsored by: