Git for SVN Users

This page is a work in progress.  If you find an error or feel that you can make a contribution, please edit the page or – if you are not comfortable editing page – press the "M" key to leave a comment at the bottom with suggested changes/additions.  Thank you! (note: you must be logged into the wiki to edit pages or add comments)

Most OpenMRS developers are comfortable with subversion and haven't had as much experience with Git.  While there are a number of good tutorials on Git, we wanted to provide a quick reference for our developers.

Basic Tasks 

Help

Git

SVN

Git

SVN

git help______________

svn help{{______________

View content of remote repository (svn list)

Git

SVN

Git

SVN

Browse on github______________

svn list http://svn.openmrs.org/openmrs/trunk/ (http://svn.openmrs.org/openmrs/trunk/*)______________

You can browse files in your local repository with git show or git ls-files.

Checkout code

Git

SVN

Git

SVN

git clone git@github.com:username/openmrs-module-mymodule.git_____

svn checkout http://svn.openmrs.org/openmrs-modules/mymodule mymodule_______

If there is a remote branch that you want to add to your local repository, use the command:

git checkout --track origin/branchname

Get updates

Git

SVN

Git

SVN

git fetch (updates your local copy of a remote branch)
or
git pull (goes a git fetch + git merge)

svn update______________

Compare working copy to head (what have I changed?)

Git

SVN

Git

SVN

git diff______________

svn diff______________

Add new file(s)/folder(s) to version control

Git

SVN

Git

SVN

git add myfile.txt______________

svn add myfile.txt______________

Delete file(s)/folder(s)

Git

SVN

Git

SVN

rm myfile.txt
 
To remove from Git's index & add to Git ignore:
git rm --cached myfile.txt

To remove from Git's index (doesn't delete file):
git rm myfile.txt______________

svn rm myfile.txt______________

Ignore certain file(s)/folder(s)

Git

SVN

Git

SVN

.gitignore______________

svn propset svn:ignore -F .svnignore .______________

Commit changes with comment (all or some of changes in working copy)

Git

SVN

Git

SVN

git commit -m "comment"______________
git push
Note: It is better to use the command "git commit -a --signoff", which will open an editor using which you should write the commit comment.
This commit would be used as an email message and a subject and the format goes something like:
* First line is used as the subject
* Second line onwards is used as the body of the message
The --signoff option add the text:
"Signed-off-by: My Name <myemail@example.com>"
This signoff statement becomes part of the comment and will be used to track the changes done and also the copyright owners of the changes

svn commit -m "comment"______________

Get basic information about working copy (svn info)

Git

SVN

Git

SVN

cat .git/config ______________

svn info______________

Revert changes (all or some changes in working copy)

Git

SVN

Git

SVN

git reset --hard HEAD^______________

svn revert MyCode.java
or to revert the entire local copy:
svn revert --depth=infinity .______________

Create a patch (diff of working copy from head)

Git

SVN

Git

SVN

git format-patch master --stdout > my_change.patch______________

svn xxx______________

Apply a patch

Git

SVN

Git

SVN

git apply --stat my_change.patch______________

patch -p0 -i my_change.patch______________

Resolve conflicts

Git

SVN

Git

SVN

git xxx______________

svn xxx______________

Create a branch (e.g., space for new module)

Git

SVN

Git

SVN

git branch branchname
git checkout branchname
or, as a single step:
git checkout -b branchname______________

svn copy trunk branches/branchname
or to create an empty branch:
svn mkdir branches/branchname____________

Close a branch

Git

SVN

Git

SVN

git branch -d branchname______________

svn del branches/branchname______________

Tag a release

Git

SVN

Git

SVN

git tag -a tagname -m "Version tagname"______________

svn copy trunk tags/tagname______________

You can list out existing tags with git tag or search for a specific tag with git tag -l 1.9.*

Advanced Tasks

Switch working copy to new repository location

Git

SVN

Git

SVN

git remote set-url origin https://github.com/openmrs/openmrs-module-newhome.git______________

svn switch https://svn.openmrs.org/openmrs-modules/newhome______________

Detach working copy

Git

SVN

Git

SVN

git archive master | tar -x -C newlocation______________

svn export newlocation______________

Blame (show annotations / show who changed what line in what commit)

Git

SVN

Git

SVN

git blame filename______________

svn blame filename______________

Show history

Git

SVN

Git

SVN

git log______________

svn log______________

Switch to earlier revision

Git

SVN

Git

SVN

git xxx______________

svn xxx______________

Correct/change old commit message

Git

SVN

Git

SVN

git xxx______________

svn xxx______________

See Also

Related pages