Jeremiah Mahler

home

Git vs Subversion

04 Jul 2013

Why Use Git Instead of Svn?

3 Reasons to Switch to Git from Subversion

git.wiki.kernel.org GitSvnComparsion

Local Git repositories can also serve as a backup since a remote repo could be re-created from one.

Equivalent Commands

Checkout

git$ git clone git@git.example.com:hello

svn$ svn co https://svn.example.com/hello

(various other urls are possible)

Pull New Changes

git$ git pull

svn$ svn update

Commit

git$ git commit
(kept local, must git push to remote)

svn$ svn commit
(also uploads to remote)

Status

# status of repository in current directory
git$ git status

svn$ svn status

Log Messages

git$ git log

svn$ svn log

Create a New Repo

# create a new repo in the current directory
git$ git init
git$ git add README

svn$ svnadmin create /home/jeri/tmp/svn1/
svn$ svn import README file:///home/jeri/tmp/svn1/README

Getting Help

git$ git help
git$ git help add
(also has man pages)

svn$ svn help
svn$ svn help add

Assign To A Remote Repo

git$ git remote add origin git@example.com:hello
git$ git push -u origin master

svn: Automatically performed during a commit.

Revert To Earlier Version

# revert the last comits changes, leave log message and history
git$ git reset HEAD~1 <path>

# revert the last comits changes, discard log message and history
git$ git reset --hard HEAD~1 <path>

# got to a specific commit, detached head
git$ git checkout <commit id>

# discard local changes
git$ git checkout <file>

svn$ svn revert <file>

Branches

git$ git branch <branch name>
git$ git checkout <branch name>

Subversion has no support for branches although directories name branches/ are often used.

Tags

git$ git -a tag <tag name>
git$ git push --tags

Subversion has no support for tags although directories name tags/ are often used.

References

Git - SVN Crash Course

3 Reasons to Switch to Git from Subversion

git.wiki.kernel.org GitSvnComparsion