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 help ______________ |
svn help {{______________ |
View content of remote repository (svn list)
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
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 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 diff ______________ |
svn diff ______________ |
Add new file(s)/folder(s) to version control
Git |
SVN |
git add myfile.txt ______________ |
svn add myfile.txt ______________ |
Delete file(s)/folder(s)
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 |
.gitignore ______________ |
svn propset svn:ignore -F .svnignore . ______________ |
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" ______________ |
Git |
SVN |
cat .git/config ______________ |
svn info ______________ |
Revert changes (all or some changes in working copy)
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 format-patch master --stdout > my_change.patch ______________ |
svn xxx ______________ |
Apply a patch
Git |
SVN |
git apply --stat my_change.patch ______________ |
patch -p0 -i my_change.patch ______________ |
Resolve conflicts
Git |
SVN |
git xxx ______________ |
svn xxx ______________ |
Create a branch (e.g., space for new module)
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 branch -d branchname ______________ |
svn del branches/branchname ______________ |
Tag a release
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
Detach working copy
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 blame filename ______________ |
svn blame filename ______________ |
Show history
Git |
SVN |
git log ______________ |
svn log ______________ |
Switch to earlier revision
Git |
SVN |
git xxx ______________ |
svn xxx ______________ |
Correct/change old commit message
Git |
SVN |
git xxx ______________ |
svn xxx ______________ |
See Also