Git and Mercurial Cheat Sheet February 01, 2015
Illustration from unDraw Our team supports a large number of applications, ranging from legacy apps in SVN, to more recent apps in Mercurial, to our latest projects in Git.
Inspired by the excellent (but very thorough) Mercurial to Git Rosetta stone , here is a bare bones, back to basics, KISS mapping between Hg and Git of the most common operations I use on a day to day basis.
Init Add Remote edit paths in .hg/hgrc
git remote add origin [email protected] :<username>/<repo-name>.git
Clone hg clone <url>
git clone <url>
Pull Push Diff hg diff
git diff
ORgit diff HEAD
(to diff both staged and unstaged)hg diff -r 20:21 ./src/filename
git diff <hash>..<hash> -- ./src/filename
... coming ...
git diff master...<hash>
(to diff RHS with common ancestor)
See incoming/outgoing commits hg in
git fetch && git log master..FETCH_HEAD
hg out
git fetch && git log FETCH_HEAD..master
Commit hg ci -m"Commit message"
git commit -am"Commit message"
Interactively commit part of working copy hg record
git add --patch && git commit
Branches hg branch <branch-name>
git checkout -b <branch-name>
hg up <branch-name>
git checkout <branch-name>
hg push --new-branch
git push origin <branch-name> -u
hg branches
git branch -a
hg commit --close-branch
# delete local branchgit branch -d <branch-name>
then # delete remote branch (NB the colon)git push origin :<branch-name>
also # remove remote tracking branches that no longer existgit fetch -p
# show commits from branchhg log -b <branch-name>
git reflog show <branch-name>
Merge hg merge <branch-name or commit number/hash>
git merge <branch-name or commit hash>
Shelve/stash hg shelve
git stash
hg unshelve
git stash pop
Clear working copy Rollback hg rollback
git reset HEAD~
Remove ignored files that are already committed hg forget "set:hgignore() and not ignored()"
git ls-files --ignored --exclude-standard | xargs git rm --cached
Like what you've read? Why not subscribe to my mailing list to get my latest articles by email.
I respect the privacy of your email address. You can unsubscribe at any time.
Written by Chris Colborne , an Aussie software engineer from Brisbane, Australia. Follow me on Twitter