Getting Started with Darcs

Among the plethora of emerging version control systems -- Subversion, Arch, Monotone and so on -- Darcs stands out for its simplicity and thoughtful design.

With darcs you can be productive within minutes; the same cannot be said for Arch or even Subversion. Let's see:

    $ mkdir ~/myproject
    $ cd ~/myproject
    $ darcs init

You now have a Darcs repository! Let's do something with it:

    $ touch myfile
    $ darcs add -r *
    $ darcs record -am "Initial import."
    Finished recording patch 'Initial import.'

If that record command is taking too long, then you may prefer this:

    $ darcs record --verbose -am "Initial import."

Now your repository contains all your files. Let's look at the changelog:

    $ darcs changes
    Thu Nov 25 06:26:19 CET 2004 johndoe@example.com
      * Initial import.

Note how Darcs generates a GNU-style changelog for you automatically.

Where are the revision numbers, you ask? Well, they don't exist, because they're not needed. Darcs is changeset-oriented, not file-oriented. You can refer to a changeset by name, date, or a special hash identity.

Now, where's the server? You need a server to share your repository, right? Nearly -- every repository is a potential server, as long as it's accessible either through the file system, through SSH/SFTP, HTTP or email. Let's check out a small remote repo to play with:

(NOTE: This repo does not seem to exist - 18th Nov 2007)

    $ darcs get http://www.ScannedInAvian.org/repos/wikiwiki
(This URL is not accessible now. -- gphilip)
    Copying patch 47 of 47... done!
    Applying patches to the "working" directory...
    ..........................................................................
    Finished getting.

We now have a complete copy of a remote repo. Let's make a modification:

  $ cd wikiwiki
  $ echo 'adding new line to file' >>scribble
  $ darcs whatsnew --summary
  M ./scribble +1
  $ darcs whatsnew
  {
  hunk ./scribble 2
  +adding new line to file
  }

This last output, by the way, is Darcs' patch format. A "hunk" is a line-based diff. Other types of changes that may be contained in a changeset include renames, moves and binary changes. (Yes, you can also get a GNU-patch-compatible output similar to "cvs diff", with darcs diff --unified.)

Now let's commit and push the changes back to the remote repository:

   $ darcs record -am "Added critical new line."
   Finished recording patch 'Added critical new line.'
   $ darcs send -a
   Creating patch to http://www.ScannedInAvian.org/repos/wikiwiki...
   Sending by email to wikiwiki@scannedinavian.org
   Successfully sent patch bundle to wikiwiki@scannedinavian.org.

See your changes

Some Key Features

Darcs changesets aren't just GNU patches; they have context, which means, for example, that someone can check out a repository, move a file foo.c into the directory bar/ and commit; meanwhile, another person, working on an older copy of the same repository, edits foo.c (which is still in its old location) and commits that. Darcs knows that this edit should apply to foo.c in the new location -- and unlike CVS, you don't need to do anything similar to cvs update if you're committing files that have been changed on the server. In other words, people can freely commit changes, and the only kind of visible "conflict" will occur when you actually edit the exact same line.

Unlike CVS and Subversion, but like Arch and Monotone, Darcs is a distributed version control system. Repositories are islands which are constantly out of sync with each other, and Darcs' patch commutation system takes care of integrating the changes that flow between them.

This system has several extremely useful effects:

Related Pages

Non-English

DarcsWiki: GettingStarted (last edited 2007-11-18 18:04:14 by CPE00131030fe87-CM0014e825d674)