Differences between revisions 38 and 61 (spanning 23 versions)
Revision 38 as of 2009-07-04 21:14:46
Size: 10249
Editor: abuehl
Comment: mention subrepos
Revision 61 as of 2013-09-02 20:00:50
Size: 10233
Editor: WagnerBruna
Comment: remove spam
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
Mercurial's decentralized development model can be confusing to new users. This page attempts to illustrate some of the basic concepts.
See the [[Tutorial]] for step-by-step instructions.

''(Translations:
[[BrazilianPortugueseUnderstandingMercurial|Brazilian Portuguese]],
[[ChineseUnderstandingMercurial|Chinese]],
[[FrenchUnderstandingMercurial|French]],
[[GermanUnderstandingMercurial|German]],
[[ItalianUnderstandingMercurial|Italian]],
[[JapaneseUnderstandingMercurial|Japanese]],
[[KoreanUnderstandingMercurial|Korean]],
[[RussianUnderstandingMercurial|Russian]],
[[SpanishUnderstandingMercurial|Spanish]],
[[ThaiUnderstandingMercurial|Thai]]
)''
#pragma section-numbers 2
= Understanding Mercurial =
Mercurial's decentralized development model can be confusing to new users. This page attempts to illustrate some of the basic concepts. See the [[Tutorial]] for step-by-step instructions.
Line 20: Line 7:
== What's in a Repository ==
== What's in a repository ==
Line 48: Line 34:

The store contains the '''complete''' history of the project. Unlike traditional [[SCM|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.
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.
Line 54: Line 38:
== Committing Changes ==

When you [[Commit|commit]], the state of the working directory relative to its [[Parent|parents]] is recorded as a new [[ChangeSet|changeset]] (also called a new "[[Revision|revision]]"):
== Committing changes ==
When you [[Cmd:commit|commit]], the state of the working directory relative to its parents is recorded as a new [[ChangeSet|changeset]] (also called a new "[[Revision|revision]]"):
Line 84: Line 67:
Line 87: Line 69:
== Revisions, Changesets, Heads, and Tip ==

Mercurial groups related changes to multiple files into single atomic [[ChangeSet|changesets]], which are revisions of the whole project.
These each get a sequential [[RevisionNumber|revision number]]. Because Mercurial allows distributed parallel development, these revision numbers may disagree between users. So Mercurial also assigns each revision a global [[ChangeSetID|changeset ID]]. Changeset IDs are 40-digit hexadecimal numbers, but they can be abbreviated to any unambiguous prefix, like "e38487".
== Revisions, changesets, heads, and tip ==
Mercurial groups related changes to multiple files into single atomic [[ChangeSet|changesets]], which are revisions of the whole project.  These each get a sequential [[RevisionNumber|revision number]]. Because Mercurial allows distributed parallel development, these revision numbers may disagree between users. So Mercurial also assigns each revision a global [[ChangeSetID|changeset ID]]. Changeset IDs are 40-digit hexadecimal numbers, but they can be abbreviated to any unambiguous prefix, like "e38487".
Line 115: Line 95:

Branches and [[Merge|merges]] in the revision history can occur at any point. Each unmerged branch creates a new [[Head|head]] of the revision history.
Here, revisions 5 and 6 are heads. Mercurial considers revision 6 to be the [[Tip|tip]] of the repository, the head with the highest revision number.
Revision 4 is a [[MergeChangeset|merge changeset]], as it has ''two'' parent changesets (revisions 2 and 3).

== Cloning, Making Changes, Merging, Pulling and Updating ==
Branches and [[Merge|merges]] in the revision history can occur at any point. Each unmerged branch creates a new [[Head|head]] of the revision history. Here, revisions 5 and 6 are heads. Mercurial considers revision 6 to be the [[Tip|tip]] of the repository, the head with the highest revision number. Revision 4 is a [[MergeChangeset|merge changeset]], as it has ''two'' parent changesets (revisions 2 and 3).

== Cloning, making changes, merging, pulling and updating ==
Line 132: Line 108:

Bob [[Clone|clones]] this repo, and ends up with a complete, independent, local copy of Alice's store
and a clean checkout of the tipmost revision d in his working directory:
Bob clones this repo, and ends up with a complete, independent, local copy of Alice's store and a clean checkout of the tipmost revision d in his working directory:
Line 144: Line 118:

Bob can now work independently of Alice. He then [[Commit|commits]] two changes e and f:
Bob can now work independently of Alice. He then commits two changes e and f:
Line 157: Line 130:

Alice then makes her own change g in parallel, which causes her repository store to diverge from Bob's, thus
creating a [[Branch|branch]]:
Alice then makes her own change g in parallel, which causes her repository store to diverge from Bob's, thus creating a [[Branch|branch]]:
Line 170: Line 141:

Bob then [[Pull|pulls]] Alice's repo to synchronize. This copies all of Alice's changes into Bob's repository store
(here, it's just a single change g). Note that Bob's working directory is '''not''' changed
by the pull:
Bob then pulls Alice's repo to synchronize. This copies all of Alice's changes into Bob's repository store (here, it's just a single change g). Note that Bob's working directory is '''not''' changed by the pull:
Line 187: Line 155:
Line 190: Line 157:
Bob then does a [[Merge|merge]], which combines the last change he was working on (f) with the
tip in his repository. Now, his working directory has two parent revisions (f and g):
Bob then does a [[Merge|merge]], which combines the last change he was working on (f) with the tip in his repository. Now, his working directory has two parent revisions (f and g):
Line 207: Line 173:

After examining the result of the merge in his working directory and making sure the merge is
perfect, Bob commits the result and ends up with a new [[MergeChangeset|merge changeset]] h in his
store:
After examining the result of the merge in his working directory and making sure the merge is perfect, Bob commits the result and ends up with a new [[MergeChangeset|merge changeset]] h in his store:
Line 228: Line 191:
Line 247: Line 209:

Note that Alice's working directory was not changed by the pull. She has to do an [[Update|update]] to synchronize
her working directory to the merge changset h. This changes the parent changeset of her working directory to
changeset h and updates the files in her working directory to revision h.
Note that Alice's working directory was not changed by the pull. She has to do an [[Update|update]] to synchronize her working directory to the merge changset h. This changes the parent changeset of her working directory to changeset h and updates the files in her working directory to revision h.
Line 268: Line 227:
Line 271: Line 229:

== A Decentralized System ==
== A decentralized system ==
Line 293: Line 249:

Unlike a centralized version control system in which experimentation
can be disastrous, with a DVCS like Mercurial, you just clone and
experiment. If you like the results, push them back, otherwise
wipe the cloned repository and try something else.
Unlike a centralized version control system in which experimentation  can be disastrous, with a DVCS like Mercurial, you just clone and  experiment. If you like the results, push them back, otherwise  wipe the cloned repository and try something else.
Line 301: Line 252:

Many SVN/CVS users expect to host related projects together in one repository. This is really not what hg was made for, so you should try a different way of working. This especially means, that you cannot check out only one directory of a repository.

If you absolutely need to host multiple projects in a kind of meta-repository though, you could try the [[subrepos|Subrepositories]] feature that was introduced with Mercurial 1.3 or the older ForestExtension.
Many SVN/CVS users expect to host related projects together in one repository. This is really not what Mercurial was made for, so you should try a different way of working. In particular, this means that you cannot check out only one directory of a repository.

If you absolutely need to host multiple projects in a kind of meta-repository though, you could try the [[Subrepository|Subrepositories]] feature that was introduced with Mercurial 1.3 or the older ForestExtension.
Line 308: Line 257:

----
[[BrazilianPortugueseUnderstandingMercurial|Brazilian Portuguese]], [[CzechUnderstandingMercurial|Czech]], [[GermanUnderstandingMercurial|Deutsch]], [[FrenchUnderstandingMercurial|Français]], [[ItalianUnderstandingMercurial|Italiano]], [[RussianUnderstandingMercurial|Russian]], [[SpanishUnderstandingMercurial|Spanish]], [[ThaiUnderstandingMercurial|Thai]], [[ChineseUnderstandingMercurial|中文]], [[JapaneseUnderstandingMercurial|日本語]], [[KoreanUnderstandingMercurial|한국어]]

Understanding Mercurial

Mercurial's decentralized development model can be confusing to new users. This page attempts to illustrate some of the basic concepts. See the Tutorial for step-by-step instructions.

1. What's in a repository

Mercurial repositories contain a working directory coupled with a store:

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.

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

2. Committing changes

When you commit, the state of the working directory relative to its parents is recorded as a new changeset (also called a new "revision"):

Note here that revision 4 is a branch of revision 2, which was the revision in the working directory. Now revision 4 is the working directory's parent.

3. 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".

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. Revision 4 is a merge changeset, as it has two parent changesets (revisions 2 and 3).

4. Cloning, making changes, merging, pulling and updating

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

Bob clones this repo, and ends up with a complete, independent, local copy of Alice's store and a clean checkout of the tipmost revision d in his working directory:

Bob can now work independently of Alice. He then commits two changes e and f:

Alice then makes her own change g in parallel, which causes her repository store to diverge from Bob's, thus creating a branch:

Bob then pulls Alice's repo to synchronize. This copies all of Alice's changes into Bob's repository store (here, it's just a single change g). Note that Bob's working directory is not changed by the pull:

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 in his repository. Now, his working directory has two parent revisions (f and g):

After examining the result of the merge in his working directory and making sure the merge is perfect, Bob commits the result and ends up with a new merge changeset h in his store:

Now if Alice pulls from Bob, she will get Bob's changes e, f, and h into her store:

Note that Alice's working directory was not changed by the pull. She has to do an update to synchronize her working directory to the merge changset h. This changes the parent changeset of her working directory to changeset h and updates the files in her working directory to revision h.

Now Alice and Bob are fully synchronized again.

5. 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 (see CommunicatingChanges):

Unlike a centralized version control system in which experimentation can be disastrous, with a DVCS like Mercurial, you just clone and experiment. If you like the results, push them back, otherwise wipe the cloned repository and try something else.

6. What Mercurial can't do

Many SVN/CVS users expect to host related projects together in one repository. This is really not what Mercurial was made for, so you should try a different way of working. In particular, this means that you cannot check out only one directory of a repository.

If you absolutely need to host multiple projects in a kind of meta-repository though, you could try the Subrepositories feature that was introduced with Mercurial 1.3 or the older ForestExtension.

For a hands-on introduction to using Mercurial, see the Tutorial.


Brazilian Portuguese, Czech, Deutsch, Français, Italiano, Russian, Spanish, Thai, 中文, 日本語, 한국어

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