From Mercurial to Git ... (commands mapping)   27 Nov 2010

In the past 2 years, I had the chance to learn lots about using Mercurial. I used many Mercurial tricks in real action, including 'Queues' , 'Rebasing', 'Transplanting' and I had to figure out strange situations with merges and conflicts. Thanks to the maintenance of Transifex.net's upstream repository and to the hosting of some of my own projects at Bitbucket, I got more experience on it. But unfortunately, if you want to contribute to open source projects, there is always the need to learn more than the basics :S! So, I also started to read about Git (as it was a more popular DVCS). That had happened a year ago :). But as I hadn't dived into the dark paths, now I found some time to do it. By reading the documentation I thought that it would be nice to come up with a mapping of some of the commands for the two DVCSes. This will not be complete or explicit and will include my point of view, so it may contain some mistakes and misdirections. Feel free to comment on it.

Git Mercurial
git init hg init .
git add <new_file> hg add <new_file> (only if the file is not tracked yet.)
git add <file>; git commit (already tracked file with modifications) hg commit (Mercurial automatically adds the modified file in index)
git checkout HEAD hg update tip
git tag <tag_name> <branch_name|commit_hash|other_tag> hg tag <tag_name> <changeset_num|changeset_hash|other_tag>
git checkout <commit_hash|branch_name|tag> hg update <changeset_hash|changeset_num|tag>
git fetch hg pull
git pull hg pull -u
git reset --hard hg revert -a --no-backup
git clone <URL> <target_name> hg clone <URL> <target_name>
git merge hg merge
git cherry-pick <commit_hash|tag|branch_head_ref> hg transplant <changeset_num|changeset_hash|tag>
git bisect hg bisect
git rebase <branch_name> (applied to another branch) hg rebase -b <a changeset on the source "branch"> -d tip (Mercurial may have more than one heads in one branch unlike Git!)
git stash hg shelve
git revert <commit_hash|tag|branch_name> hg backout <changeset_num|changeset_hash|tag>
git am <mbox> hg mimport -m &ltmbox>
git commit --amend hg qimport -r tip ; hg qrefresh -e ; hg qfinish tip