Mercurial for Git users

So far I have been a heavy git user, but recently I found myself working on a project using Mercurial for version control so I needed to get up to speed very fast.

This cheatsheet might be of help to someone who finds themselves in a similar situation.

Start a new repo

hg init

Clone a remote repo

hg clone <URL>

Mercurial (along with other VCSs apparently), unlike git, does not require staging of files. Once a file has been added to the repo, it can then be committed.In Mercurial, you can list the files along with the commit command in order to commit a subset of the changes.

Add a file to the repo

hg add <file(s)>

Commit changes to the repo

hg commit [file(s)] [-m "Commit message"]

Show your current revision (similar to commit in git)

hg id -i

Commit deleted files

hg remove --after

Undo your last commit but keep the changes

hg rollback

Branching is important for collaborating in Git , in Mercurial you will mainly be creating branches and merging them into the default branch (Mercurial’s version of git’s master branch).

Creating a branch

hg branch <name>

Switch to another branch

hg up <name>

Update you branch to match the newest version in your local repo

hg update <name>

Pull all Changes

hg pull 

Pull a specific Commit

hg pull -r <hash>

Push a new branch

hg push --new-branch

Check your current branch

hg identify -b

Merge branches

hg merge <name>

 

Branch Status (`git status`)

hg resolve -i (lists files with resolved/unresolved conflicts)

 

On branches, Mercurial will not allow you to delete a branch after it has been merged because When you have merged the two branches, the merge commit depends on the existence of its two parent commits. That means that you can't remove the commits making up the merged branch unless you also delete the merge commit.

If GUI’s are your thing you can find a list of Mercurial clients here https://www.mercurial-scm.org/wiki/OtherTools

 

 
Madra David
Madra David
1 minute read
TL;DR

Share this article

Next Post

An introduction to Day trading

Previous Post

Why Django Is Ideal for Startups

I send out tips on how to improve your website's performance

I send out tips on how to improve your website's performance

user-image

Published juin 26 2018

by Madra David