Mercurial HOWTO
From IthrynWiki
Notes:
- Mercurial works on files and directories BUT directories that are empty are invisible to it.
- <path> here means one file or directory, <paths...> a series of them, [<path>] or [<paths...] means files are optional.
- hg help is your first friend, man hg is your second, the Mercurial wiki your third.
- Customize your usage with ~/.hgrc
- There are lots of useful extensions.
- Look at .hgignore.
- There are other cheat sheets.
Contents |
Help
| Action | Command |
|---|---|
| Help | hg help |
| Help for command | hg help <command>
hg <command> --help |
Add, Remove, Rename, Copy
| Action | Command | |
|---|---|---|
| Add specific files | hg add [<paths...>] | |
| Remove files from version control (don't delete from file system) | hg remove <paths...> | |
| Remove files from version control (delete from file system) | hg remove -f <paths...> | |
| Remove files that've been deleted from file system | hg remove -A <paths...> | |
| Add all new files, remove all delete ones. | hg addremove | |
| Move/rename files | hg move <path> <new path> | |
| Copy files | hg copy <path> <new path> |
Commit changes
| Action | Command |
|---|---|
| Commit changes | hg commit [<paths...>] |
| Commit with a given message | hg commit -m <message> [<paths...>] |
| Commit as a particular user | hg commit -u <user> [<paths...>] |
| Revert all changes (don't commit) | hg revert -a |
| Revert specific changes (don't commit) | hg revert <paths...> |
Viewing changes
| Action | Command |
|---|---|
| View changes between working set and repository tip. | hg diff [<paths...>] |
| View changes between working set and specific revision. | hg diff -r <revision> [<paths...>] |
| View changes between revisions. | hg diff -r <revision> -r <revision> [<paths...>] |
| What's changed in working set. | hg status [<paths...>] |
| Ignore what's changed | edit .hgignore |
| Log | hg log [<paths...>] |
| Log summary | hg log -q |
| Log with file listing | hg log -v |
| Annotations | hg annotate <path> |
Working set
| Action | Command |
|---|---|
| Change working set to tip (last revision) | hg update |
| Change working set, discarding any current work. | hg update -C |
| Change working set to specific revision | hg update -r <revision> |
| Change working set to specific branch | hg update[-C] -r <branch> |
| See which branches are available for merging | hg heads |
| Merge next available branch. | hg merge |
| Merge a branch | hg merge -r <branch> |
Sharing
Every repository has an associated working copy. Cloning repositories copies them AND creates a working copy. The paths passed to these commands can be file paths or URLs. The default on init and clone is the current directory. The default on push and pull is the repository cloned from.
| Action | Command |
|---|---|
| Make a new repository | hg init [<path>] |
| Copy from an existing repository | hg clone <source path> [<destination path>] |
| Clone a "bare" repository (no working set). | hg clone -U <source path> [<destination path>] |
| Copy only a specific branch of an existing repository. | hg clone -r <branch> <source path> [<destination path>] |
| Copy existing repository to a new location. | hg clone . <destination path> |
| Grab changes from another repository. Doesn't change working set (see update above). | hg pull [<path>] |
| Grab changes AND updating working set. | hg pull -u [<path>] |
| Grab changes for a specific branch. | hg pull -r <branch> [<path>] |
| See which changes will come in on a pull. | hg incoming [<path>] |
| Publish changes. | hg push [<path>] |
| Publish changes to a specific branch. | hg push -r <branch> [<path>]
(Sometimes needs -f <grumble>) |
| See which changes will go out on a push. | hg outgoing [<path>] |
Branches and tags
| Action | Command |
|---|---|
| Tag a revision | hg tag [-r <revision] <tag> |
| Delete a tag | hg tag -r <tag> |
| Rename a tag | hg tag -f -r <old tag> <new tag> |
| List tags | hg tags |
| Create a branch | hg branch <branch>
hg commit -m "Branch <branch>" |
| Delete a branch | hg commit --close-branch <branch>
(Yeah should be hg branch -d <branch>) |
| Rename a branch | Can't yet :( |
| List branches | hg branches |
