Differences between revisions 115 and 116
Revision 115 as of 2008-03-24 23:27:30
Size: 184
Editor: abuehl
Comment:
Revision 116 as of 2008-03-29 00:01:52
Size: 5338
Editor: abuehl
Comment: merging immediate subpages into here (but not those in CategoryTipsAndTricks)
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
#pragma section-numbers 3
Line 4: Line 5:
|| [[Include(TipsAndTricks/Index)]] ||<^>[[Include(TipsAndTricks/Subpages)]] || [[TableOfContents]]

=== Undo an "hg add" ===
{{{
hg revert # take out of source control
hg rm -f # remove it
}}}

=== Save a push URL so that you don't need to enter it each time ===
It is possible to store a default [:Push:push] URL that will be used when you type just "hg push". Edit .hg/hgrc and add something like:

{{{
[paths]
default-push = ssh://hg@example.com/path
}}}

=== 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:

 * http://selenic.com/hg/rss-log/
 * http://selenic.com/hg/rss-log/tip/mercurial/hgweb/hgweb_mod.py

=== Create links to snapshots of files and tarballs ===
If you want to create web links to [:Tag:tagged] or [:Tip:tip] versions of a [:Repository:repository] or a file, you can do so like this:

 * http://selenic.com/hg/archive/tip.tar.gz
 * http://selenic.com/hg/archive/0.9.3.zip
 * http://selenic.com/hg/raw-file/tip/COPYING
 * http://selenic.com/hg/raw-file/0.9.3/COPYING

=== Configuring Mercurial ===
See in [wiki:mercurial.ini].

=== Abbreviate command options ===
It is possible to abbreviate command options:
{{{
hg revert --no-b
hg revert --no-backup
}}}

=== Ignore files from Emacs/XEmacs ===
Add the following to [:.hgignore]:

{{{
syntax: glob
*~

syntax: regexp
(.*/)?\#[^/]*\#$
}}}

=== Make a clean copy of a source tree, like CVS export ===
{{{
hg clone source export
rm -rf export/.hg
}}}
or using the archive command
{{{
cd source
hg archive ../export
}}}

The same thing, but for a [:Tag:tagged] release:

{{{
hg clone --noupdate source export-tagged
cd export-tagged
hg update mytag
rm -rf .hg
}}}
or using the archive command
{{{
cd source
hg archive -r mytag ../export-tagged
}}}

=== 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
}}}

=== Generating color diff output with extdiff and colordiff ===
You can use the [:ExtdiffExtension:extdiff extension] to get colorized diff output. If you've enabled the extension and have colordiff installed, the following [:.hgrc:hgrc] snippet will create a new {{{cdiff}}} command:

{{{
[defaults]
# suppress noisy extdiff header message
cdiff = -q

[extdiff]
cmd.cdiff = colordiff
opts.cdiff = -uprN
}}}

=== 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:

 {{{
[DEFAULT]
HOME = /home/myuser

[ui]
ignore.mine = %(HOME)s/.hgignore.mine
style = %(HOME)s/.hg-styles/hg-map-cmdline.color

[paths]
dotfiles = %(HOME)s/

[extensions]
# Avoid the [DEFAULT] extension bug
HOME = !
}}}

=== Using FileMerge.app/opendiff as the diff program (OS X) ===
The Developer Tools for OS X provide the excellent graphical diff program "File``Merge.app". The provided command-line wrapper "opendiff" for "File``Merge.app" will not work with ExtdiffExtension. Instead, use the script [http://ssel.vub.ac.be/ssel/internal:fmdiff fmdiff] which wraps "File``Merge.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]
hgext.extdiff =

[extdiff]
cmd.opendiff = fmdiff
}}}
and use
{{{
$ hg opendiff ...
}}}

=== 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

{{{
hgdi ()
{
  for i in `hg status -marn "$@"`
  do
    diff -ubwd <(hg cat "$i") "$i"
  done
}
}}}

You can also use the extdiff extension to call GNU diff from Mercurial.

=== 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.

Tips and Tricks

(see also [:FAQ], [wiki:CategoryTipsAndTricks CategoryTipsAndTricks])

TableOfContents

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:push] URL that will be used when you type just "hg push". Edit .hg/hgrc and add something like:

[paths]
default-push = ssh://hg@example.com/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:

If you want to create web links to [:Tag:tagged] or [:Tip:tip] versions of a [:Repository:repository] or a file, you can do so like this:

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]:

syntax: glob
*~

syntax: regexp
(.*/)?\#[^/]*\#$

8. Make a clean copy of a source tree, like CVS export

hg clone source export
rm -rf export/.hg

or using the archive command

cd source
hg archive ../export

The same thing, but for a [:Tag:tagged] release:

hg clone --noupdate source export-tagged
cd export-tagged
hg update mytag
rm -rf .hg

or using the archive command

cd 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

You can use the [:ExtdiffExtension:extdiff extension] to get colorized diff output. If you've enabled the extension and have colordiff installed, the following [:.hgrc:hgrc] snippet will create a new cdiff command:

[defaults]
# suppress noisy extdiff header message
cdiff = -q

[extdiff]
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:

  • [DEFAULT]
    HOME = /home/myuser
    
    [ui]
    ignore.mine = %(HOME)s/.hgignore.mine
    style = %(HOME)s/.hg-styles/hg-map-cmdline.color
    
    [paths]
    dotfiles = %(HOME)s/
    
    [extensions]
    # 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 [http://ssel.vub.ac.be/ssel/internal:fmdiff 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]
hgext.extdiff =

[extdiff]
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

hgdi ()
{
  for i in `hg status -marn "$@"`
  do
    diff -ubwd <(hg cat "$i") "$i"
  done
}

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.

TipsAndTricks (last edited 2016-12-05 11:14:36 by ArneBab)