Git and Mercurial Cheat Sheet
February 01, 2015Illustration 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.
edit paths in .hg/hgrc
git remote add origin [email protected]:<username>/<repo-name>.git
hg clone <url>
git clone <url>
git 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
git fetch && git log master..FETCH_HEAD
git fetch && git log FETCH_HEAD..master
hg ci -m"Commit message"
git commit -am"Commit message"
Interactively commit part of working copy
git add --patch && git commit
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
git branch -a
hg commit --close-branch
|# delete local branch|
git branch -d <branch-name>
# delete remote branch (NB the colon)
git push origin :<branch-name>
# remove remote tracking branches that no longer exist
git fetch -p
|# show commits from branch|
hg log -b <branch-name>
git reflog show <branch-name>
hg merge <branch-name or commit number/hash>
git merge <branch-name or commit hash>
git stash pop
Clear working copy
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