1119
Comment: cvs export tag
|
6572
link to hgrc manpage
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
#pragma section-numbers 3 = Tips and Tricks = ''(see also [:FAQ], [:HOWTOs], [wiki:Self:CategoryTipsAndTricks CategoryTipsAndTricks])'' || [[TableOfContents]] || [[Include(/Index)]] || === 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 [http://www.selenic.com/mercurial/hgrc.5.html .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 (.*/)?\#[^/]*\#$ }}} |
|
Line 2: | Line 57: |
Line 7: | Line 61: |
or using the archive command {{{ cd source hg archive ../export }}} |
|
Line 8: | Line 67: |
=== The same thing, but for a tagged release === | The same thing, but for a [:Tag:tagged] release: |
Line 11: | Line 70: |
hg clone source export-tagged | hg clone --noupdate source export-tagged |
Line 13: | Line 72: |
hg update -C mytag | hg update mytag |
Line 16: | Line 75: |
or using the archive command {{{ cd source hg archive -r mytag ../export-tagged }}} |
|
Line 17: | Line 81: |
=== See diffs when editing commit message with VIM === Make a private copy of the 'hgeditor' script provided with mercuiral and replace the call to the editor with following command: |
=== 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}}}). |
Line 22: | Line 85: |
vim "+e $HGTMP/diff" '+set buftype=help filetype=diff' "+vsplit $HGTMP/msg" || exit $? | hg status -nu0 | grep -z pattern | xargs -0r ls -l |
Line 25: | Line 88: |
This will start up VIM in vertical split mode with commit message in the left pane and diff in the right pane. The {{{buftype=help}}} setting for diff window tells vim to exit when all other windows are closed, so when you write and quit the log with {{{:x}}} ({{{:wq}}} - they are equivalent), vim exits. If you have syntax highlight set up, the diff will be properly highlighted. | 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 }}} |
Line 27: | Line 93: |
This setting is suitable for wide terminals. If you have a narrow terminal, you may want to replace the {{{+vsplit}}} above with {{{+split}}} or add {{{nowrap}}} to the {{{+set}}}. | === 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. === 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 === Removing the working directory of a repository === If you forgot to specify {{{-U}}} on "hg [:Clone:clone]", doing {{{ hg update null }}} will remove everything from the [:WorkingDirectory:working directory] of the [:Repository:repository]. See also [:Update:update]. ~-([http://selenic.com/pipermail/mercurial/2008-March/018332.html reference])-~ === 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 {{{ [defaults] diff = --unified 8 }}} to the defaults section of your [:.hgrc]. However, this only affects the diff command itself. ~-([http://www.selenic.com/mercurial/bts/issue1076 reference])-~ |
Tips and Tricks
(see also [:FAQ], [:HOWTOs], [wiki:CategoryTipsAndTricks CategoryTipsAndTricks])
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 [http://www.selenic.com/mercurial/hgrc.5.html .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:
4. 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:
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.
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:clone]", doing
hg update null
will remove everything from the [:WorkingDirectory:working directory] of the [:Repository:repository]. See also [:Update:update]. ([http://selenic.com/pipermail/mercurial/2008-March/018332.html reference])
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
[defaults] diff = --unified 8
to the defaults section of your [:.hgrc]. However, this only affects the diff command itself. ([http://www.selenic.com/mercurial/bts/issue1076 reference])