- Undo an "hg add"
- Save a push URL so that you don't need to enter it each time
- Track changes to a repository with RSS
- Create links to snapshots of files and tarballs
- Configuring Mercurial
- Abbreviate command options
- Ignore files from Emacs/XEmacs
- Make a clean copy of a source tree, like CVS export
- One liner to remove unknown files with a pattern
- Generating color diff output with extdiff and colordiff
- Using config substitution and the [DEFAULT] section of hgrc
- Using FileMerge.app/opendiff as the diff program (OS X)
- hg diff does not support -foo option like gnu diff does
- Handling binary files
- Diagnose "abort: Error" messages
- Removing the working directory of a repository
- Setting the default context for diff to something larger
1. Undo an "hg add"
hg revert # take out of source control
hg rm -f # remove it
2. Save a push URL so that you don't need to enter it each time
It is possible to store a default push URL that will be used when you type just "hg push". Edit .hg/hgrc and add something like:
default-push = ssh://firstname.lastname@example.org/path
3. Track changes to a repository with RSS
You can track changes to projects and individual files with RSS feeds from hgweb. Here are some examples:
4. Create links to snapshots of files and tarballs
5. Configuring Mercurial
See in wiki:mercurial.ini.
6. Abbreviate command options
It is possible to abbreviate command options:hg revert --no-b
hg revert --no-backup
7. Ignore files from Emacs/XEmacs
Add the following to .hgignore:
8. Make a clean copy of a source tree, like CVS export
hg clone source export
rm -rf export/.hg
or using the archive commandcd source
hg archive ../export
The same thing, but for a tagged release:
hg clone --noupdate source export-tagged
hg update mytag
rm -rf .hg
or using the archive commandcd source
hg archive -r mytag ../export-tagged
9. One liner to remove unknown files with a pattern
To make these work, replace the ls -l with the command you wish to execute (ie. rm). You can also tweak the parameters passed to hg status to filter by something other than unknown files (see hg help status).
hg status -nu0 | grep -z pattern | xargs -0r ls -l
The above command requires a current version of GNU grep. If you don't have one, you can use the following:hg status -nu | grep pattern | tr '\n' '\0' | xargs -0r ls -l
10. Generating color diff output with extdiff and colordiff
# suppress noisy extdiff header message
cdiff = -q
cmd.cdiff = colordiff
opts.cdiff = -uprN
11. Using config substitution and the [DEFAULT] section of hgrc
The hgrc manpage gives a passing description of the [DEFAULT] section header but gives no notion of how one might use this (or the possible caveats). Here's an example:
%(NAME)s is substituted in configuration values if NAME is defined in the current section
Names defined in the [DEFAULT] section appear in all other configuration sections (unless overridden in a particular section)
- In most sections, names not specifically used are ignored however...
The [extensions] will attempt to load any names in it has extensions
Putting a name in [DEFAULT] usually breaks the configuration as the name is likely not a valid extension
Placing a name under [DEFAULT] requires that you keep the [extensions] section from trying to load it.
Here's an example of the usage:
HOME = /home/myuser
ignore.mine = %(HOME)s/.hgignore.mine
style = %(HOME)s/.hg-styles/hg-map-cmdline.color
dotfiles = %(HOME)s/
# Avoid the [DEFAULT] extension bug
HOME = !
12. Using FileMerge.app/opendiff as the diff program (OS X)
The Developer Tools for OS X provide the excellent graphical diff program "FileMerge.app". The provided command-line wrapper "opendiff" for "FileMerge.app" will not work with ExtdiffExtension. Instead, use the script fmdiff which wraps "FileMerge.app" so that it responds like the usual diff program. Once fmdiff is in your path, just add the below to your .hgrc file[extensions]
cmd.opendiff = fmdiff
and use$ hg opendiff ...
13. hg diff does not support -foo option like gnu diff does
I use the following bash function to put the diff options I like most
for i in `hg status -marn "$@"`
diff -ubwd <(hg cat "$i") "$i"
You can also use the extdiff extension to call GNU diff from Mercurial.
14. Handling binary files
as stated in BinaryFiles, you need to have a tool which manages binary merge. Joachim Eibl's new kdiff3 version ships a version qt4 version (on windows called "kdiff3-QT4.exe") which recognizes binary files. Pressing "cancel" and "do not save" leaves you with the version of the file you have currently in the filesystem. See also on CvsConcepts.
15. Diagnose "abort: Error" messages
I get a cryptic "abort: Error" message while pushing to my server. This is not enough info to figure out the problem. I tried hg -v --debug push but I still don't get anything more informative. What can I do?
- disable cgitb in hgweb on the server
run with --debug --traceback on the client
- check the error logs on the server
16. Removing the working directory of a repository
If you forgot to specify -U on "hg clone", doinghg update null
17. Setting the default context for diff to something larger
hg diff outputs 3 lines of context per default (see "hg help diff"). To change the default to for example 8 lines, add
diff = --unified 8to the defaults section of your .hgrc. However, this only affects the diff command itself. (reference)