Sunday, February 13, 2011

A small Subversion guide for Git users

A recurring problem for us Git users is that we tend to forget the good old Subversion tricks. We want to do some patch on some old code in a Subversion repo, and suddenly we've got no idea how to work around.

Here's a quick guide:

> git pull
> svn update


> git add new_file
svn add new_file

> git add changed_file
N/A: SVN automatically adds all modifications to the index. If you don't want to commit it, don't change it.

> git commit; git push (you always have to do these together):
> svn commit

> git revert [SHA]
> svn merge -c -[R] .


> git branch branch_name
> svn copy url_to_project/trunk url_to_project/branches/branch_name


> git tag tag_name
> svn copy url_to_project/trunk url_to_project/tags/tag_name


> git checkout branch_name
> svn switch url_to_project/branches/branch_name/


> git merge branch 
svn merge -r[start]:[end] url_to_project/branches/branch_name .
(Note that you have to keep track of at which revision you made the branch, and that the result will always be squashed. Renames and moves will create conflicts).

> git rebase ...
Forget about it :)


Please add other neat SVN tricks to the comments if you can think of any good ones ;)