Skip to content

Instantly share code, notes, and snippets.

@cortesben
Last active December 11, 2024 00:18
Show Gist options
  • Save cortesben/016cd401faae5a8dae59 to your computer and use it in GitHub Desktop.
Save cortesben/016cd401faae5a8dae59 to your computer and use it in GitHub Desktop.
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/

@fmilovanov
Copy link

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

@pkdavidson
Copy link

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
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
Copy link

-u in pull is to update

@cortesben
Copy link
Author

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
Copy link

⚠️ hg record requires an extension which is deprecated.

@jmaton
Copy link

jmaton commented Aug 20, 2020

please add:

hg identify -b
identify the branch you're on

@hramrach
Copy link

how do you do
git show

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment