Here are some useful commands for everyday tasks with mercurial.
Mercurial: Basic Commands
hg clone http://example.com/project1 project1-repo Creates a local copy of a remote repository.
hg pull Brings changes from the remote repositoriy to our local repository.
hg status Shows the changed, deleted und untracked files.
hg add -A . Marks all the changes in the path for commiting. It adds the changes to the staging area.
hg commit -m <Message> Commits the changes in the local repository. This commit is local, you have to push your changes to send it to the remote repository.
hg push Sends changes from our local repository to the remote repository.
hg push -r default Sends changes of the default branch from our local repository to the remote repository.
? Reverts all the local changes on the path.
Mercurial: Common use cases
Analyse the logs
hg glog It shows a very nice diagram with the history of the changesets
It comes an important issue, when you are working on another ticket
We use the shelve extension for this. Please follow the configuration steps here.
hg shelve Save changes
hg shelve --list List saved changes
hg unshelve Restore the changes
Add all the files in the current directory and subdirectories
find . -exec hg add '{}' \;
List all the changed and added files in a branch:
hg update feature/321
hg status --rev 9787 --added --modified where 9787 is the revision where the branch was created.
Restore files
TODO
Remove untracked files or directories
TODO
Remove last Commit
If the commit wasn't pushed, you can use:
hg strip <hash of the commit>
If it doesn't work you would have to activate the strip extension. Here is the homepage of this extension .
Revert an old commit
You use the backout command. It makes a revert of all the data changes -the history is untouched- in one commit. The delta is calculate using that revision and the current revision of the repository. Due to this, I prefer to update the repository to the first commit after the wrong commit and from there do the backout with TortoiseHg.
A > B > C > D > E
If I want to revert B, I update the repository to C.
Revert a merge
If it wasn't pushed, you can strip it.
If it was pushed, there isn't any easy way to revert it. Please read here and tale into account this warning:
"Backing out a merge will lead to trouble if you ever want to redo the merge. The only safe way to deal with a bad merge is to abandon the branch."
Here is a very good explanation for Git applicable to Hg