Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Mercurial command cheat sheet

Mercurial Commands

Commands Description
hg pull get latest changes like git pull use flags like -u IDK why yet
hg add only for new files
hg commit add changes to commit with -m for message just like git
hg addremove adds new files and removes file not in your file system
hg incoming see changes commited by others
hg outgoing see local commits
hg commit --amend same as git commit --amend
hg record filename shows history of changes to file uses extension
hg merge like a git merge http://hgbook.red-bean.com/read/a-tour-of-mercurial-merging-work.html
hg log -r tip tip changelog
hg log -l 5 last 5 changelog statuses
hg status -m show modified files only
hg status -r show removed files only
hg status -a show added files only
hg strip "0000" remove commit from history and delete changes before push, if pushed you are fucked
hg log -u email@accout.com see all account commits | type -v for a verbose version
hg diff -r 0000:0000 /dir/location/path Diff versions of same file from different CHANGESET
hg diff | less; hg commit show changes committed
hg out See what is not pushed to remote branch
hg update 0000 CHANGESET = 0000 or branchname
hg checkout branch works like a git checkout branch
hg record shows record of pending changes
hg update -C resets your head and removes commits not pushed like git reset --hard
hg backout 0000 CHANGESET = 0000 like a git revert tag/hash
hg blame or hg annotate same as a git blame
hg bisect lets you test inbetween commits to find bugs http://mercurial.selenic.com/wiki/BisectExtension
hg shelve like a git stash (Requires the ShelveExtension or the AtticExtension.)
hg graft --edit 0000 lets you pick what changes to push to default or commit CHANGESET = 0000 git cherry-pick <commit> http://selenic.com/hg/help/graft
hg graft --edit 0000::0005 add a series of commits from 0000 to 0005 as a batch
hg heads shows changes in child and parent branches
hg identify --num current changeset
hg branch feature go to default branch and use this command to create a new branch namded "feature" based off of it
hg commit --close-branch -m 'closing this branch' Inside branch you want to close commit this and push so branch disapears and keeps your coworkers happy
note Hg .hgignore, syntax: glob is the same behaviour as git's .gitignore.

Branching

http://stevelosh.com/blog/2009/08/a-guide-to-branching-in-mercurial/

@vinodlinux91

This comment has been minimized.

Copy link

vinodlinux91 commented Sep 26, 2016

Good hard work and This is Usefull for the begginers of the mercurial

@martimorta

This comment has been minimized.

Copy link

martimorta commented Nov 3, 2017

Thanks, I'd add:
hg push

@luismaqueda

This comment has been minimized.

Copy link

luismaqueda commented Dec 28, 2017

Good work! It is very useful for me. I turned out crazy looking for an equivalent to git stash, so thanks :) !

@ghost

This comment has been minimized.

Copy link

ghost commented Mar 23, 2018

Thanks for this.

@vlablack

This comment has been minimized.

Copy link

vlablack commented May 4, 2018

Will be nice to add:
hg di > 1.patch

@fmilovanov

This comment has been minimized.

Copy link

fmilovanov commented May 23, 2018

I'm afraid this is only for those who already know Mercurial. For those who don't (or forgot it), this is gibberish.

@pkdavidson

This comment has been minimized.

Copy link

pkdavidson commented May 25, 2018

Gibberish, seriously? The title is cheat sheet, not Learn Hg or complete help for Hg.
Why would you even land here if you didn't have a clue about Hg or Git. Makes no sense to attack an author who by all other comments, has shared a useful product. If you don't like it, move on or show us how you think it should be done. But to disparage someone sharing their work product? sheesh...

I agree adding hg push would be a useful addition.
A number of folks still use a central repo when working in an Enterprise environment.

@nufue

This comment has been minimized.

Copy link

nufue commented Jul 30, 2018

I would suggest merging hg out and hg outgoing, as one is an alias for the other.

@alpeshspatel

This comment has been minimized.

Copy link

alpeshspatel commented Sep 11, 2018

-u in pull is to update

@cortesben

This comment has been minimized.

Copy link
Owner Author

cortesben commented May 7, 2019

Thanks everyone for the kind comments. I was forced to use Mercurial at a job a few years ago and that is when I created this. I really appreciate the love and feedback to enhance this. By all means fork and make it your own. I was working full time for almost two years using Mercurial, it's not a bad alternative to git at all.

@combinatorist

This comment has been minimized.

Copy link

combinatorist commented Jan 24, 2020

⚠️ hg record requires an extension which is deprecated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.