Differences between revisions 1 and 58 (spanning 57 versions)
Revision 1 as of 2006-12-18 21:23:37
Size: 4594
Editor: mpm
Comment:
Revision 58 as of 2013-08-31 11:33:47
Size: 386
Editor: CecilAROC
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
== What's in a Repository ==

Mercurial repositories contain a working directory coupled with a store:

{{{#!dot
digraph G {
 rankdir = BT
 background="#999999";
 subgraph cluster_0 {
  style=filled;
  color=lightgrey;
  node [style=filled,color=white];
  edge [style=invis];
  "main.c"-> "main.h" -> ".hgignore" -> ".hgtags"
  label="working directory";
 }
 subgraph cluster_1 {
  style=filled;
  color="#eeeeee";
  node [shape=box,style=filled,color=lightgray];
  "rev 0" -> "rev 1" -> "rev 2" -> "rev 3";
  label = "store";
 }
}
}}}

The working directory contains a copy of the project's files at a given point in time, ready for editing. Because tags and ignored files are revision-controlled, they are also included.

The store contains the '''complete''' history of the project. Unlike traditional SCMs, where there's only one central copy of this history,
every working directory is paired with a private copy of the history. This allows development to go on in parallel.

== Revisions, Changesets, Heads, and Tip ==

Mercurial groups related changes to multiple files into single atomic '''changesets''', which are '''revisions''' of the whole project.
These each get a sequential revision number. Because Mercurial allows distributed parallel development, these revision numbers may disagree between users. So Mercurial also assigns each revision a global '''changeset ID'''. Changeset IDs are 40-digit hexadecimal numbers, but they can be abbreviated to any unambiguous prefix, like "e38487".

{{{#!dot
digraph {
   rankdir = LR
   node [shape=box]
   "rev 0:838e" -> "rev 1:34ef" -> "rev 2:4563"
   "rev 1:34ef" -> "rev 3:fe56"
   "rev 2:4563" -> "rev 4:ac98"
   "rev 3:fe56" -> "rev 4:ac98"
   "rev 4:ac98" -> "rev 5:0345"
   "rev 4:ac98" -> "rev 6:19e3 (tip)"
   label="example history"
}
}}}

Branches and merges in the revision history can occur at any point. Each unmerged branch creates a new '''head''' of the revision history.
Here, revisions 5 and 6 are heads. Mercurial considers revision 6 to be the '''tip''' of the repository, the head with the highest revision number.

== Cloning, Making Changes, and Pulling ==

Let's start with a user Alice, who has a store that looks like:

{{{#!dot
digraph {
   label="Alice's Repo"
   rankdir = LR
   node [shape=box]
   a->b->c->d
}
}}}

Bob '''clones''' this repo, and ends up with a complete copy:

{{{#!dot
digraph {
   label="Bob's Repo"
   rankdir = LR
   node [shape=box]
   a->b->c->d
}
}}}

Bob then '''commits''' a couple changes:

{{{#!dot
digraph {
   label="Bob's Repo"
   rankdir = LR
   node [shape=box]
   a->b->c->d->e->f
   e [color=blue]
   f [color=blue]
}
}}}

Alice then makes her own change in parallel:

{{{#!dot
digraph {
   label="Alice's Repo"
   rankdir = LR
   node [shape=box]
   a->b->c->d->g
   g [color=red]
}
}}}

Bob then '''pulls''' Alice's repo to synchronize. This copies all of Alice's changes into Bob's repo:

{{{#!dot
digraph {
   label="Bob's Repo"
   rankdir = LR
   node [shape=box]
   a->b->c->d->e->f
   e [color=blue]
   f [color=blue]
   d->g
   g [color=red;label="g (tip)"]
}
}}}

Because Alice's '''g''' is the newest head in Bob's repository, it's now the '''tip'''. Bob then does a merge which combines the last change he was working on ('''f''') with the tip, commits the result, and ends up with:

{{{#!dot
digraph {
   label="Bob's Repo"
   rankdir = LR
   node [shape=box]
   a->b->c->d->e->f
   e [color=blue]
   f [color=blue]
   d->g
   g [color=red]
   f->h
   g->h
   h [color=green;label="h (tip)"]
}
}}}

Now if Alice '''pulls''' from Bob, she will get Bob's changes e, f, and h, and they will be fully synchronized:

{{{#!dot
digraph {
   label="Alice's Repo"
   rankdir = LR
   node [shape=box]
   a->b->c->d->g
   d->e->f
   e [color=blue]
   f [color=blue]
   g [color=red]
   f->h
   g->h
   h [color=green;label="h (tip)"]
}
}}}

== A Decentralized System ==

Mercurial is a completely decentralized system, and thus has no internal notion of a central repository. Thus users are free to define their own topologies for sharing changes:

{{{#!dot
digraph {
   Alice -> Central
   Central -> Alice
   Bob -> Central
   Alice -> Bob
   Alice -> Carl
   Carl -> Central
   Bob -> Carl
   Carl -> Bob
   "Carl's Laptop" -> Carl
   Carl -> "Carl's Laptop"
   "Carl's Laptop" -> Central
   Central [style=fill;color=blue;label="Main Public Repo"]
   label="A Mercurial Network"
}
}}}
The writer is called Nickolas Courtright but people always misspell it. One of his favorite hobbies is baseball but he can't make it his profession. North Dakota is the only place he's been residing in and he loves every day living there. Supervising is his day job now. He's been working on his website for some time now. Check it out here: http://www.youtube.com/watch?v=Fo3gdIFkUCM

The writer is called Nickolas Courtright but people always misspell it. One of his favorite hobbies is baseball but he can't make it his profession. North Dakota is the only place he's been residing in and he loves every day living there. Supervising is his day job now. He's been working on his website for some time now. Check it out here: http://www.youtube.com/watch?v=Fo3gdIFkUCM

UnderstandingMercurial (last edited 2013-09-02 20:00:50 by WagnerBruna)