Differences between revisions 29 and 30
Revision 29 as of 2007-01-09 11:38:01
Size: 15696
Editor: ny9
Comment:
Revision 30 as of 2007-01-09 13:05:10
Size: 19123
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
(see also TipsAndTricks)
Line 2: Line 4:
[[TableOfContents]]
Line 3: Line 6:
== General Questions ==

=== What is the license of the project? ===

The project license is available under the GNU General Public License, v2. See COPYING in the release for more details.
Line 5: Line 14:
=== I did an ''hg pull'' and my working directory is empty! === === I did an hg pull and my working directory is empty! ===
Line 8: Line 17:
directory. ''hg pull'' pulls all new changes from a remote repository directory. {{{hg pull}}} pulls all new changes from a remote repository
Line 15: Line 24:
To update your working directory, run ''hg update''. If you're sure you
want to update your working directory on a pull, you can also use [=hg
pull -u]. This will refuse to merge or overwrite local changes.

=== I did an ''hg revert'' and my working directory still has changes in it! ===

You've probably done an ''hg update -m'', which means your working directory now has two parents according to ''hg parents''. A subsequent ''hg revert'' will revert your working directory /back to the primary parent/, thus leaving you with the differences between the two parents.
To update your working directory, run {{{hg update}}}. If you're sure you
want to update your working directory on a pull, you can also use
{{{hg pull -u}}}. This will refuse to merge or overwrite local changes.

=== I want to retrieve an old version of my project, what do I do? ===

You want {{{hg update -C <version>}}}, which will clobber your current version with the requested version.

You '''don't''' want {{{hg revert <version>}}}, which reverts changes in your working directory back to that version, but '''keeps''' the current parents for the next checkin. This command exists for undoing changes in current versions, not for working on old versions.

=== hg status shows changed files but hg diff doesn't! ===

{{{hg status}}} reports when file '''contents''' or '''flags''' have changed relative to '''either''' parent. {{{hg diff}}} only reports changed '''contents''' relative to the first parent. You can see flag information with the {{{--git}}} option to {{{hg diff}}} and deltas relative to the other parent with {{{-r}}}.

=== hg export or log -p shows a strange diff for my merge! ===

The diff shown by {{{hg export}}} and {{{hg log}}} is always against the first parent for consistency. Also, the files listed are only the files that have changed relative to ''both'' parents.

=== I did an hg revert and my working directory still has changes in it! ===

You've probably done an {{{hg merge}}}, which means your working directory now has two parents according to {{{hg parents}}}. A subsequent {{{hg revert}}} will revert your working directory ''back to the primary parent'', thus leaving you with the differences between the two parents. {{{hg update -C}}} will revert the left files.
Line 24: Line 47:
''hg update -C''. {{{hg update -C}}}.
Line 28: Line 51:
The easiest thing to do is run ''hg clone -U'' which will create a fresh clone The easiest thing to do is run {{{hg clone -U}}} which will create a fresh clone
Line 31: Line 54:
'''Note''': you might want to copy hgrc file from your old repository.

=== I committed a change containing nuclear launch codes, how do I delete it permanently? ===

If you've just committed it, and you haven't done any other commits or pulls since, you may be able to use {{{rollback}}} to undo the last commit transaction:

{{{
$ hg rollback
rolling back last transaction
}}}

If you've made other changes but you haven't yet published it to the world, you can do something like the following:

{{{
$ hg clone -r <untainted-revision> tainted-repo untainted-repo
}}}

This will get you a new repo without the tainted change or the ones that follow it. You can import the further changes with {{{hg export}}} and {{{hg import}}} or by using the TransplantExtension. See TrimmingHistory for possible future approaches.

If you've already pushed your changes to a public repository that people have cloned from, the genie is out of the bottle. Good luck cleaning up your mess.

=== I tried to check in an empty directory and it failed! ===

Mercurial doesn't track directories, it only tracks files. Which works for just about everything, except directories with no files in them. As empty directories aren't terribly useful and it makes the system much simpler, we don't intend to fix this any time soon. A couple workarounds:

 * add a file, like "this-dir-intentionally-left-blank"
 * create the directory with your Makefiles or other build processes

=== I want to get an email when a commit happens! ===

See CommitHook for an example.

=== I'd like to put only some few files of a large directory tree (home dir for instance) under mercurial's control, and it is taking forever to diff or commit ===

Just do a {{{
printf "syntax: glob\n*\n" > .hgignore
}}}
or, if you are using 0.7 or below, {{{
printf ".*\n" > .hgignore
}}}

This will make hg ignore all files except those explicitly added.

=== Why is the modification time of files not restored on checkout? ===

If you use automatic build tools like make or distutils, some built files
might not be updated if you checkout an older revision of a file.
Additionally a newer changeset might have an older commit timestamp due to
pulling from someone else or importing patches somebody has done some time
ago, so checking out a ''newer'' changeset would have to make the files
''older'' in this case.

If you need predictable timestamps you can use ''hg archive'', which can do
something like a checkout in a separate directory. Because this directory is
newly created, there is nothing like switching to a different changeset
afterwards, therefore the above mentioned problems don't apply here.
Line 33: Line 113:
=== What are revision numbers, changeset I``Ds, and tags? === === What are revision numbers, changeset IDs, and tags? ===
Line 70: Line 150:
easy. Simply run ''hg pull'' and ''hg update -m'' and commit the result. easy. Simply run {{{hg pull}}} and {{{hg update -m}}} and commit the result.
Line 90: Line 170:
into your working directory. Thus you run ''hg update -m'' and Mercurial into your working directory. Thus you run {{{hg update -m}}} and Mercurial
Line 129: Line 209:
upsteam. Publish this tree with ''hg serve'' or hgweb.cgi or use [=hg
push] to push it to another publicly availabe repository.
upsteam. Publish this tree with {{{hg serve}}} or hgweb.cgi or use
{{{
hg push}}}
to push it to another publicly availabe repository.
Line 161: Line 242:
this file and then commit it for it to take effect. The ''hg tag''
command will do this for you and "hg tags" will show the currently
this file and then commit it for it to take effect. The {{{hg tag}}}
command will do this for you and {{{hg tags}}} will show the currently
Line 173: Line 254:
You can use "hg tag" command with an option ''-l'' or ''--local''. This You can use "hg tag" command with an option {{{-l}}} or {{{--local}}}. This
Line 185: Line 266:
=== How do I use "branch tags"? ===

CVS-style branch tags don't make sense in a distributed SCM like Mercurial because '''everything is a branch'''. This is one reason why most Mercurial users will keep a separate repository for each branch. But if you need to keep multiple branches in one repository, normal tags can be made to do the trick
if you use good practices.

Though tags directly refer only to individual revisions, they can also be used to specify the heads of the branches they're on. To see the tags associated with each head, run ''hg heads -b''. To check out the head of a branch associated with a tag, you can use ''hg update -b tagname''.

Note that it's possible for multiple heads to inherit the same tag, which will happen if there's a branch point after that tag that hasn't been remerged. In this case, Mercurial will complain and you'll need to explicitly specify which revision you want.

It's also possible for a head to inherit multiple unrelated tags from different branches. This generally isn't a problem.
=== What if multiple lines with different revisions use the same tag name in .hgtags? ===

Only the last line where the tag appears is taken into account.
The behavior is identical when this happens in .hg/localtags.
Line 200: Line 275:
Report it to the mercurial mailing list, mercurial@selenic.com. Report it to the mercurial mailing list, mercurial@selenic.com or in the bug tracker
http://www
.selenic.com/mercurial/bts/
Line 231: Line 307:
Offsets in revlogs are currently tracked with 32 bits, so a revlog for
a single file can currently not grow beyond 4G.
Line 239: Line 312:
File names cannot contain the null character. Committer addresses File names cannot contain the null character or newlines. Committer addresses
Line 276: Line 349:
=== What about Windows line endings vs. Unix line endings? ===

See EncodeDecodeFilter.

=== What about keyword replacement (i.e. $Id$)? ===

See KeywordPlan.
Line 278: Line 359:
Mercurial diffs are calculated rather differently than those generated by the traditional diff algorithm (but with output that's completely compatible with patch of course). The algorithm is an optimized C implementation based on Python's [difflib http://python.org/doc/2.4.1/lib/module-difflib.html], Mercurial diffs are calculated rather differently than those generated by the traditional diff algorithm (but with output that's completely compatible with patch of course). The algorithm is an optimized C implementation based on Python's [http://python.org/doc/2.4.1/lib/module-difflib.html difflib],

(see also TipsAndTricks)

Mercurial Frequently Asked Questions

TableOfContents


1. General Questions

1.1. What is the license of the project?

The project license is available under the GNU General Public License, v2. See COPYING in the release for more details.

2. Common Problems

2.1. I did an hg pull and my working directory is empty!

There are two parts to Mercurial: the repository and the working directory. hg pull pulls all new changes from a remote repository into the local one but doesn't alter the working directory.

This keeps you from upsetting your work in progress, which may not be ready to merge with the new changes you've pulled and also allows you to manage merging more easily (see below about best practices).

To update your working directory, run hg update. If you're sure you want to update your working directory on a pull, you can also use hg pull -u. This will refuse to merge or overwrite local changes.

2.2. I want to retrieve an old version of my project, what do I do?

You want hg update -C <version>, which will clobber your current version with the requested version.

You don't want hg revert <version>, which reverts changes in your working directory back to that version, but keeps the current parents for the next checkin. This command exists for undoing changes in current versions, not for working on old versions.

2.3. hg status shows changed files but hg diff doesn't!

hg status reports when file contents or flags have changed relative to either parent. hg diff only reports changed contents relative to the first parent. You can see flag information with the --git option to hg diff and deltas relative to the other parent with -r.

2.4. hg export or log -p shows a strange diff for my merge!

The diff shown by hg export and hg log is always against the first parent for consistency. Also, the files listed are only the files that have changed relative to both parents.

2.5. I did an hg revert and my working directory still has changes in it!

You've probably done an hg merge, which means your working directory now has two parents according to hg parents. A subsequent hg revert will revert your working directory back to the primary parent, thus leaving you with the differences between the two parents. hg update -C will revert the left files.

If you're trying to switch between revisions in history, you probably want hg update -C.

2.6. I want a clean, empty working directory

The easiest thing to do is run hg clone -U which will create a fresh clone without checking out a working copy.

Note: you might want to copy hgrc file from your old repository.

2.7. I committed a change containing nuclear launch codes, how do I delete it permanently?

If you've just committed it, and you haven't done any other commits or pulls since, you may be able to use rollback to undo the last commit transaction:

$ hg rollback
rolling back last transaction

If you've made other changes but you haven't yet published it to the world, you can do something like the following:

$ hg clone -r <untainted-revision> tainted-repo untainted-repo

This will get you a new repo without the tainted change or the ones that follow it. You can import the further changes with hg export and hg import or by using the TransplantExtension. See TrimmingHistory for possible future approaches.

If you've already pushed your changes to a public repository that people have cloned from, the genie is out of the bottle. Good luck cleaning up your mess.

2.8. I tried to check in an empty directory and it failed!

Mercurial doesn't track directories, it only tracks files. Which works for just about everything, except directories with no files in them. As empty directories aren't terribly useful and it makes the system much simpler, we don't intend to fix this any time soon. A couple workarounds:

  • add a file, like "this-dir-intentionally-left-blank"
  • create the directory with your Makefiles or other build processes

2.9. I want to get an email when a commit happens!

See CommitHook for an example.

2.10. I'd like to put only some few files of a large directory tree (home dir for instance) under mercurial's control, and it is taking forever to diff or commit

Just do a

printf "syntax: glob\n*\n" > .hgignore

or, if you are using 0.7 or below,

printf ".*\n" > .hgignore

This will make hg ignore all files except those explicitly added.

2.11. Why is the modification time of files not restored on checkout?

If you use automatic build tools like make or distutils, some built files might not be updated if you checkout an older revision of a file. Additionally a newer changeset might have an older commit timestamp due to pulling from someone else or importing patches somebody has done some time ago, so checking out a newer changeset would have to make the files older in this case.

If you need predictable timestamps you can use hg archive, which can do something like a checkout in a separate directory. Because this directory is newly created, there is nothing like switching to a different changeset afterwards, therefore the above mentioned problems don't apply here.

3. Terminology

3.1. What are revision numbers, changeset IDs, and tags?

Mercurial will generally allow you to refer to a revision in three ways: by revision number, by changeset ID, and by tag.

A revision number is a simple decimal number that corresponds with the ordering of commits in the local repository. It is important to understand that this ordering can change from machine to machine due to Mercurial's distributed, decentralized architecture.

This is where changeset IDs come in. A changeset ID is a 160-bit identifier that uniquely describes a changeset and its position in the change history, regardless of which machine it's on. This is represented to the user as a 40 digit hexadecimal number. As that tends to be unwieldy, Mercurial will accept any unambiguous substring of that number when specifying versions. It will also generally print these numbers in "short form", which is the first 12 digits.

You should always use some form of changeset ID rather than the local revision number when discussing revisions with other Mercurial users as they may have different revision numbering on their system.

Finally, a tag is an arbitrary string that has been assigned a correspondence to a changeset ID. This lets you refer to revisions symbolically.

3.2. What are branches, heads, and the tip?

The central concept of Mercurial is branching. A 'branch' is simply an independent line of development. In most other version control systems, all users generally commit to the same line of development called 'the trunk' or 'the main branch'. In Mercurial, every developer effectively works on a private branch and there is no internal concept of 'the main branch'.

Thus Mercurial works hard to make repeated merging between branches easy. Simply run hg pull and hg update -m and commit the result.

'Heads' are simply the most recent commits on a branch. Technically, they are changesets which have no children. Merging is the process of joining points on two branches into one, usually at their current heads. Use "hg heads" to find the heads in the current repository.

The 'tip' is the most recently changed head, and also the highest numbered revision. If you have just made a commit, that commit will be the tip. Alternately, if you have just pulled from another repository, the tip of that repository becomes the current tip.

The 'tip' is the default revision for many commands such as update, and also functions as a special symbolic tag.

4. General Usage

4.1. How does merging work?

The merge process is simple. Usually you will want to merge the tip into your working directory. Thus you run hg update -m and Mercurial will incorporate the changes from tip into your local changes.

The first step of this process is tracing back through the history of changesets and finding the 'common ancestor' of the two versions that are being merged. This is done on a project-wide and a file by file basis.

For files that have been changed in both projects, a three-way merge is attempted to add the changes made remotely into the changes made locally. If there are conflicts between these changes, the user is prompted to interactively resolve them.

Mercurial uses a helper tool for this, which is usually found by the hgmerge script. Example tools include tkdiff, kdiff3, and the classic RCS merge.

After you've completed the merge and you're satisfied that the results are correct, it's a good idea to commit your changes. Mercurial won't allow you to perform another merge until you've done this commit as that would lose important history that will be needed for future merges.

4.2. What are some best practices for distributed development with Mercurial?

First, merge often! This makes merging easier for everyone and you find out about conflicts (which are often rooted in incompatible design decisions) earlier.

Second, don't hesitate to use multiple trees locally. Mercurial makes this fast and light-weight. Typical usage is to have an incoming tree, an outgoing tree, and a separate tree for each area being worked on.

The incoming tree is best maintained as a pristine copy of the upstream repository. This works as a cache so that you don't have to pull multiple copies over the network. No need to check files out here as you won't be changing them.

The outgoing tree contains all the changes you intend for merge into upsteam. Publish this tree with hg serve or hgweb.cgi or use hg push to push it to another publicly availabe repository.

Then, for each feature you work on, create a new tree. Commit early and commit often, merge with incoming regularly, and once you're satisfied with your feature, pull the changes into your outgoing tree.

4.3. How do I import from a repository created in a different SCM?

See ConvertingRepositories for various tips.

4.4. What about Windows support?

See WindowsInstall for getting started using Windows.

5. Tags

5.1. How do tags work in Mercurial?

Tags work slightly differently in Mercurial than most revision systems. The design attempts to meet the following requirements:

  • be version controlled and mergeable just like any other file
  • allow signing of tags
  • allow adding a tag to an already committed changeset
  • allow changing tags in the future

Thus Mercurial stores tags as a file in the working dir. This file is called .hgtags and consists of a list of changeset IDs and their corresponding tags. To add a tag to the system, simply add a line to this file and then commit it for it to take effect. The hg tag command will do this for you and hg tags will show the currently effective tags.

Note that because tags refer to changeset IDs and the changeset ID is effectively the sum of all the contents of the repository for that change, it is impossible in Mercurial to simultaneously commit and add a tag. Thus tagging a revision must be done as a second step.

5.2. What if I want to just keep local tags?

You can use "hg tag" command with an option -l or --local. This will store the tag in the file .hg/localtags, which will not be distributed or versioned. The format of this file is identical to the one of .hgtags and the tags stored there are handled the same.

5.3. How do tags work with multiple heads?

The tags that are in effect at any given time are the tags specified in each head, with heads closer to the tip taking precedence. Local tags override all other tags.

5.4. What if multiple lines with different revisions use the same tag name in .hgtags?

Only the last line where the tag appears is taken into account. The behavior is identical when this happens in .hg/localtags.

6. Bugs and Features

6.1. I found a bug, what do I do?

Report it to the mercurial mailing list, mercurial@selenic.com or in the bug tracker http://www.selenic.com/mercurial/bts/

6.2. What should I include in my bug report?

Enough information to reproduce or diagnose the bug. If you can, try using the hg -v and hg -d switches to figure out exactly what Mercurial is doing.

If you can reproduce the bug in a simple repository, that is very helpful. The best is to create a simple shell script to automate this process, which can then be added to our test suite.

6.3. Can Mercurial do <x>?

If you'd like to request a feature, send your request to mercurial@selenic.com. As Mercurial is still very new, there are certainly features it is missing and you can give us feedback on how best to implement them.

Be sure to see ToDo and MissingFeatures to see what's already planned and where we need help.

7. Technical Details

7.1. What limits does Mercurial have?

Mercurial currently assumes that single files, indices, and manifests can fit in memory for efficiency.

There should otherwise be no limits on file name length, file size, file contents, number of files, or number of revisions.

The network protocol is big-endian.

File names cannot contain the null character or newlines. Committer addresses cannot contain newlines.

Mercurial is primarily developed for UNIX systems, so some UNIXisms may be present in ports.

7.2. How does Mercurial store its data?

The fundamental storage type in Mercurial is a "revlog". A revlog is the set of all revisions of a named object. Each revision is either stored compressed in its entirety or as a compressed binary delta against the previous version. The decision of when to store a full version is made based on how much data would be needed to reconstruct the file. This lets us ensure that we never need to read huge amounts of data to reconstruct a object, regardless of how many revisions of it we store.

In fact, we should always be able to do it with a single read, provided we know when and where to read. This is where the index comes in. Each revlog has an index containing a special hash (nodeid) of the text, hashes for its parents, and where and how much of the revlog data we need to read to reconstruct it. Thus, with one read of the index and one read of the data, we can reconstruct any version in time proportional to the object size.

Similarly, revlogs and their indices are append-only. This means that adding a new version is also O(1) seeks.

Revlogs are used to represent all revisions of files, manifests, and changesets. Compression for typical objects with lots of revisions can range from 100 to 1 for things like project makefiles to over 2000 to 1 for objects like the manifest.

7.3. How does Mercurial handle binary files?

See BinaryFiles.

7.4. What about Windows line endings vs. Unix line endings?

See EncodeDecodeFilter.

7.5. What about keyword replacement (i.e. $Id$)?

See KeywordPlan.

7.6. How are Mercurial diffs and deltas calculated?

Mercurial diffs are calculated rather differently than those generated by the traditional diff algorithm (but with output that's completely compatible with patch of course). The algorithm is an optimized C implementation based on Python's [http://python.org/doc/2.4.1/lib/module-difflib.html difflib], which is intended to generate diffs that are easier for humans to read rather than be 'minimal'. This same algorithm is also used for the internal delta compression.

In the course of investigating delta compression algorithms, we discovered that this implementation was simpler and faster than the competition in our benchmarks and also generated smaller deltas than the theoretically 'minimal' diffs of the traditional diff algorithms. This is because the traditional algorithm assumes the same cost for insertions, deletions, and unchanged elements.

7.7. How are manifests and changesets stored?

A manifest is simply a list of all files in a given revision of a project along with the nodeids of the corresponding file revisions. So grabbing a given version of the project means simply looking up its manifest and reconstructing all the file revisions pointed to by it.

A changeset is a list of all files changed in a check-in along with a change description and some metadata like user and date. It also contains a nodeid to the relevent revision of the manifest.

7.8. How do Mercurial hashes get calculated?

Mercurial hashes both the contents of an object and the hash of its parents to create an identifier that uniquely identifies an object's contents and history. This greatly simplifies merging of histories because it avoid graph cycles that can occur when a object is reverted to an earlier state.

All file revisions have an associated hash value. These are listed in the manifest of a given project revision, and the manifest hash is listed in the changeset. The changeset hash is again a hash of the changeset contents and its parents, so it uniquely identifies the entire history of the project to that point.

7.9. What checks are there on repository integrity?

Every time a revlog object is retrieved, it is checked against its hash for integrity. It is also incidentally doublechecked by the Adler32 checksum used by the underlying zlib compression.

Running 'hg verify' decompresses and reconstitutes each revision of each object in the repository and cross-checks all of the index metadata with those contents.

But this alone is not enough to ensure that someone hasn't tampered with a repository. For that, you need cryptographic signing.

7.10. How does signing work with Mercurial?

Take a look at the hgeditor script for an example. The basic idea is to use GPG to sign the manifest ID inside that changelog entry. The manifest ID is a recursive hash of all of the files in the system and their complete history, and thus signing the manifest hash signs the entire project contents.

7.11. What about hash collisions? What about weaknesses in SHA1?

The SHA1 hashes are large enough that the odds of accidental hash collision are negligible for projects that could be handled by the human race. The known weaknesses in SHA1 are currently still not practical to attack, and Mercurial will switch to SHA256 hashing before that becomes a realistic concern.

Collisions with the "short hashes" are not a concern as they're always checked for ambiguity and are still long enough that they're not likely to happen for reasonably-sized projects (< 1M changes).

FAQ (last edited 2012-10-08 19:05:50 by mpm)