Difference between revisions of "Slicer:git-svn"

From Slicer Wiki
Jump to: navigation, search
Line 13: Line 13:
 
== Make a local clone of Slicer ==
 
== Make a local clone of Slicer ==
  
git svn clone -s -r 16923 http://svn.slicer.org/Slicer4
+
First, fork the Slicer/Slicer.git project on github into your own account (this will save space on github).
  
The -s says that slicer uses the standard trunk/tags/branches svn layout and the -r says grab the code at revision 16923 (just to keep things smaller).
+
Then, check out your own copy and associate it with slicer's svn:
The command above tries to checkout the "trunk" branch of the svn repository, so revision 16923 must exist within the "trunk" branch.  Note: use the URL http://svn.slicer.org/Slicer3 to access the Slicer3 svn repository.
 
  
Then update to get the most recent:
+
# git clone git@github.com:<user>/Slicer.git
 +
# git svn init http://svn.slicer.org/Slicer4/trunk
 +
# git update-ref refs/remotes/git-svn refs/remotes/origin/master
 +
# git svn rebase
  
cd Slicer4
+
== Optional - push it to a different github repository ==
git svn fetch
 
git checkout master
 
 
 
Jim needed an extra step here to have the checkout sit at HEAD and not at R16923
 
 
 
git svn rebase
 
 
 
== push it to github ==
 
  
 
On github, create a new repository for your account called Slicer4.
 
On github, create a new repository for your account called Slicer4.
Line 102: Line 96:
 
File deleted (using svn, just for cleanliness): http://viewvc.slicer.org/viewvc.cgi/Slicer3?view=revision&revision=15513
 
File deleted (using svn, just for cleanliness): http://viewvc.slicer.org/viewvc.cgi/Slicer3?view=revision&revision=15513
  
== Alternate import with history ==
 
Importing the full svn history is slow... One way around this is to specify a late revision number as above (and even this can take a while).
 
  
Another option is to get the history from an existing git-svn'd repo:
 
  
# git clone git@github.com:Slicer/Slicer.git
+
 
# git svn init http://svn.slicer.org/Slicer4/trunk
+
== Alternate Import from svn with History ==
# git update-ref refs/remotes/git-svn refs/remotes/origin/master
 
# git svn rebase
 
  
 
This will pull the git-svn hash history from the existing repo, (avoids calculating from the beginning), then update to the current svn revision.
 
This will pull the git-svn hash history from the existing repo, (avoids calculating from the beginning), then update to the current svn revision.
 +
 +
 +
git svn clone -s -r 16923 http://svn.slicer.org/Slicer4
 +
 +
The -s says that slicer uses the standard trunk/tags/branches svn layout and the -r says grab the code at revision 16923 (just to keep things smaller).
 +
The command above tries to checkout the "trunk" branch of the svn repository, so revision 16923 must exist within the "trunk" branch.  Note: use the URL http://svn.slicer.org/Slicer3 to access the Slicer3 svn repository.
 +
 +
 +
Then update to get the most recent:
 +
 +
cd Slicer4
 +
git svn fetch
 +
git checkout master
 +
 +
Jim needed an extra step here to have the checkout sit at HEAD and not at R16923
 +
 +
git svn rebase
 +
  
 
== More git resources ==
 
== More git resources ==

Revision as of 18:39, 21 July 2011

Home < Slicer:git-svn

Intro

As of 2011 the 3D Slicer projects use subversion (svn) for the main repositories. Many project are switching to git and many developers prefer it, but feedback is also mixed about just how easy it is for a large distributed team to standardize on a set of workflows and stick with them (much anecdotal evidence and hearsay omitted).

But, individual developers or groups can use git for their work and then commit the results back to svn. The info here provides a brief set of hints for this.

Prerequisites

Install git and git-svn on your machine (git svn is an add-on package, requiring an extra apt-get install on ubuntu).

For these instructions we'll assume you are using github so make yourself an account there (it's free and pretty simple). Configure the account with your email, name, and ssh keys. The git tutorials are never-ending, so don't try to read them all at once. The only way to get good with git is to play around with some dummy repositories while reading various documents until you feel reasonably confident with the way things work.

Make a local clone of Slicer

First, fork the Slicer/Slicer.git project on github into your own account (this will save space on github).

Then, check out your own copy and associate it with slicer's svn:

  1. git clone git@github.com:<user>/Slicer.git
  2. git svn init http://svn.slicer.org/Slicer4/trunk
  3. git update-ref refs/remotes/git-svn refs/remotes/origin/master
  4. git svn rebase

Optional - push it to a different github repository

On github, create a new repository for your account called Slicer4.

Then set up a 'git remote' (basically an alias) to your git hub repository:

git remote add pieperSlicer4 git@github.com:pieper/Slicer4.git

(of course, replace occurrences of 'pieper' with your github username!).

The following command will populate the github master with your Slicer4 master (which is based on trunk).

git push pieperSlicer4 master

Create a topic branch

The 'branchy workflow' method of git is cool because all the changes related to a topic (meaning bug fix, feature addition, refactoring...) can be encapsulated in a lightweight branch that you can easily share with others.

Create a branch called "testbranch" for implementing our topic:

git checkout -b testbranch

(use 'git branch' to list branches and see that you are currently on the testbranch).

Now do some edits. If you create a new file, add it for tracking like so:

echo "new stuff" > newfile
git add newfile

As you make the changes, commit them to your local copy and give descriptive comments:

git commit -am "ENH: added a new file with new stuff  ..."

(in reality we prefer that you don't use the -m flag and instead us your editor to write a fairly long commit message with as much detail as you can stand to type). Also be sure to start your commit message with ENH, BUG, COMP, STYLE... for compatibility with the slicer svn rules.

Whenever you want to sync this up to github, just do:

git push pieperSlicer4 testbranch

Now if you look at the github repository it will have your new branch and commits. And you can easily email the link to the diffs off to your collaborators. They can review them, or check them out, make their own clones, or (with your permission) edit and commit back to your branch.

Committing back to svn

Once you have the code from the branch just the way you want it, you can put it directly back into svn (do not merge it back into master).

Bring your local master in sync with svn by doing, essentially, the same as 'svn update':

git svn rebase

then you can commit

git svn dcommit

Note: you may need to use git commit --ammend to edit the commit message to add "ENH:", "COMP:", "BUG:" etc. to be compatible with slicer svn.

Since we're done with this branch, we can clean it up:

git branch -d testbranch

And, we can get rid of it off of github:

git push pieperSlicer4 testbranch --delete
or 
git push pieperSlicer4 :testbranch


How it looks in svn

These are normal svn operations, so once they are commited (with dcommit) they show up as normal (example here is from Slicer3):

File created: http://viewvc.slicer.org/viewvc.cgi/Slicer3?view=revision&revision=15512 File modified: http://viewvc.slicer.org/viewvc.cgi/Slicer3?view=revision&revision=15514 File deleted (using svn, just for cleanliness): http://viewvc.slicer.org/viewvc.cgi/Slicer3?view=revision&revision=15513



Alternate Import from svn with History

This will pull the git-svn hash history from the existing repo, (avoids calculating from the beginning), then update to the current svn revision.


git svn clone -s -r 16923 http://svn.slicer.org/Slicer4

The -s says that slicer uses the standard trunk/tags/branches svn layout and the -r says grab the code at revision 16923 (just to keep things smaller). The command above tries to checkout the "trunk" branch of the svn repository, so revision 16923 must exist within the "trunk" branch. Note: use the URL http://svn.slicer.org/Slicer3 to access the Slicer3 svn repository.


Then update to get the most recent:

cd Slicer4
git svn fetch
git checkout master

Jim needed an extra step here to have the checkout sit at HEAD and not at R16923

git svn rebase


More git resources

(There is more info on git than anyone can really digest - unfortunately I often find that the information you need is not exactly described by the man page or tutorial you are currently reading. The only solution is to read widely, don't believe everything you read, skip the parts that seem too wordy or abstract, and experiment a lot.)

Here are a bunch of links that may help: