Skip to content

Instantly share code, notes, and snippets.

@rebkwok
Last active June 22, 2016 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rebkwok/e480f08c8da1fc6be669e01534040263 to your computer and use it in GitHub Desktop.
Save rebkwok/e480f08c8da1fc6be669e01534040263 to your computer and use it in GitHub Desktop.

Mercurial notes in no particular order

  • Delete untracked files from working directory.
    hg purge

  • To delete just the '.orig' files (which accumulate after merging)
    hg purge -I **/*.orig --all

  • Limit log to last X commits
    hg log --limit <X>

  • Limit log to only a specific named branch
    hg log --only-branch <name>

  • Move a bookmark to a different changeset
    hg bookmark --rev <changeset> <bookmark name>

  • Similar to git stash
    hg shelve and hg unshelve

  • Similar to git cherrypick hg graft <changeset>

  • Rollback last action
    hg rollback

  • Discard changes in a specific file (similar to git checkout )
    hg revert <filename>

  • Pushing changes
    hg outgoing shows what will be pushed
    hg push pushes all changes on all branches by default (but doesn't push bookmarks)
    hg push -b <branch> pushes named branch only
    hg push -B <bookmark> push named bookmark
    hg push --new-branch> needed if your push will create a new named branch

  • Merging to @ and closing a branch

hg update @
hg merge my_branch
hg commit -m "Merge in @"
hg update my_branch
hg commit -m "Close branch my_branch" --close-branch
hg push
  • Stripping commits
    ```hg strip `` removes a changeset and any descendents
    Has no effect if already pushed; if you push a commit that needs to be stripped, you need to have everyone who's pulled that commit strip locally, then strip on bitbucket.

  • Reverting a strip
    Mercurial saves backups here: <REPO>/.hg/strip-backup/
    To recover the stripped commit:
    hg unbundle .hg/strip-backup/99aae0c100b3-9d930854-backup.hg

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