List of Equivalent Commands in Git, Mercurial, and Subversion
Whether you work in collaboration with other developers or alone, you need version control to track the changes you or others have made to your code.
The most commonly used open source version control systems are Git, Mercurial, and Subversion. There are a lot of differences between these three. The main difference is that Subversion is a centralized version control system. It uses a central server to store all files and requires developers to check out the repository, which they update from and commit to. Git and Mercurial, on the other hand, are distributed version control systems. As a result, the latter have more commands in common with each other than with Subversion.
However, similarities still exist, despite the different workflows. Although the commands used are rarely exactly the same, there are equivalent commands between these three version control systems. So, for your pleasure, we are providing you with a list — a cheat sheet if you will — of some of the most used commands in Git, Mercurial, and Subversion.
You will find this particularly useful if you are migrating from one version control system to another and need to learn the ropes in your new system.
The list below is by no means exhaustive. We'd love to hear what types of similarities you have spotted in these version control systems. Or even if you disagree with the commands.
|git add <file>||hg add <new_file> (only if the file is not tracked yet)||svn add <file> (only if the file is not tracked yet)|
|git blame <file>||hg blame <file>||svn blame <file>|
|git show <rev>:<file>||hg cat -r <rev> <file>||svn cat -r <rev> <file>|
|git clone <URL> <target_name>||hg clone <URL> <target_name>||svn checkout <URL> <target_name>|
|git commit -a||hg commit||svn commit|
|git rm <file>||hg rm <file>||svn delete <file>|
|git diff <file>||hg diff <file>||svn diff <file>|
|git show HEAD:<directory>||hg cat -r rev <directory>||svn list <directory>|
|git merge||hg merge||svn merge|
|git checkout <file or directory>||hg revert <file or directory>||svn revert <file or directory>|
|git checkout HEAD||hg update tip||svn switch <url> or svn revert <file>|
|git checkout <branch>||hg update <branch>||svn switch <url>|
|git status||hg status||svn status|
|git pull||hg pull -u||svn update|
|git init||hg init .||svnadmin create|
|git fetch||hg pull||svn update|
|git reset --hard||hg revert -a --no-backup||svn checkout -r <revision> url://path/to/repo|
|git stash||hg shelve||No equivalent, may be released in SVN 1.10?, possibly in 2017|
|git revert <commit_hash|tag|branch_name>||hg backout <changeset_num|changeset_hash|tag>||svn merge -r UPREV:LOWREV . undo range|
svn merge -c -REV . undo single revision
Which version control system suits your needs? Regardless of the choice you make, you can take them all for a test drive if you sign up for Helix TeamHub because we support all three.