Note:

This page is now obsolete.

Numpy has a native Git repository at http://github.com/numpy/numpy, and Scipy has a native Git repository at http://github.com/scipy/scipy.

The instructions on this page should not be used any more.

Preparations

Clone the Git mirror

You need to clone the Git mirror of Scipy's SVN repository first. This needs to be done only once.

git clone --origin svn git://github.com/scipy/scipy-svn.git scipy

This will take some time, as the repository (ca. 30 MB) contains Scipy's whole history.

Now you can do

git log svn/trunk

to view the commit log of Scipy's trunk. Or, list branches and tags in SVN:

git branch -r

Initializing git-svn

(Optional, for people with SVN commit access.) This is optional, but needs to be done if you want to use git-svn to commit your changes back to SVN.

git svn init -s --prefix=svn/ http://svn.scipy.org/svn/scipy
git svn rebase -l -n

This should be very fast.

... for repository cloned from elsewhere

Suppose you cloned the Scipy repository from a source different from the official SVN mirror. You can initialize git-svn also in this case, but you have to first do:

git remote add svn git://github.com/scipy/scipy-svn.git
git fetch svn

i.e. associate the "svn" remote with the SVN data. Note that the "fetch" step above does not fetch any data that you already have, so it is fast.

Using the git clone

Create a branch

There is one rule to always remember: Never work on a remote (eg. SVN) branch directly, always on a branch made from it.

Concretely, if you want to work on the trunk

# Make a branch 'work' based on trunk, and switch to it
git checkout -b work svn/trunk

You can list available branches with

git branch       # <- your branches
git branch -r    # <- remote branches

Edit and commit

For this point, things function as explained in the Git tutorial: http://www.kernel.org/pub/software/scm/git/docs/gittutorial.html

Commands typically needed:

git add FILES       # add new files
git commit FILES    # commit. If you don't supply files, supply -a to commit everything

Staying abreast SVN

To fetch new items from the SVN mirror, just do

git fetch

Then, you'll need to merge your changes with those in trunk. Two options: rebase or merge.

If you haven't published your changes, you can just use rebase:

git rebase svn/trunk

If there are conflicts, it will ask you to resolve them. After all is done, your commits will lie on top of those in SVN. Note that if one of your commits exactly matches changes made in SVN, it will silently disappear in rebasing.

An alternative is merging, which does not rewrite history,

git merge svn/trunk

XXX: but committing changes back using git-svn may be more hairy if there are merges? Also, you get duplicate commits, since SVN cannot contain merge commits

Collaboration via git

This should work similarly as in standard Git, but let's briefly mention some main points:

Publishing your branches

For example http://github.com/ and http://gitorious.org/ offer free space for publishing your work on Open-source projects.

Github is one of the most prominent providers, so we discuss it here in more detail. First, you need to have a SSH private key to upload. Check the documentation

for how to get started with this. After that, create a repository there using the web interface. And then, tell git about the location of the repository

git remote add github git@github.com:USERNAME/REPONAME.git

The address is specific to your account, so change USERNAME and REPONAME accordingly.

Finally, push your branch there:

git push github BRANCHNAME

If you want to push all your branches, use

git push github --all

Viewing other people's changes

First, tell Git about someone's branch:

git remote add pauli git://github.com/pv/scipy-work.git
git fetch pauli
git remote show pauli

Switch the working tree to it:

git checkout pauli/ticket-503-special-iv-fix

Examine what was done there:

git log svn/trunk..
git diff svn/trunk
git show bb21c
git show 7f738

If you want to hack on it yourself, again create a branch of your own:

git checkout -b ticket-503-special-iv-fix pauli/ticket-503-special-iv-fix

Dealing with changes in SVN

XXX: todo, find out and explain what to do if you have made changes to someone's stuff, and he/she has rebased against SVN in the meantime

Dealing directly with SVN

If you configured git-svn as instructed above, you can interface directly to SVN.

Warning

If you git fetch SVN commits to Git from the mirror (or indirectly from somewhere else), git-svn gets confused (this seems to no longer happen with Git 1.7.x, though). This is visible eg. the next time you try to dcommit back to SVN: you get spurious extra commits.

So every often before doing a git svn dcommit, it may be necessary to rebuild your `git-svn` database:

rm -rf .git/svn
git svn dcommit -n
An easy way to do this is to use the git-show-dcommit script given below.

Another way is to always use git svn fetch. But then you can still run into the same problem if you fetch someone else's branch.

Committing to SVN

First, read the above warning.

It is strongly suggested that you use the git-show-dcommit script below to check the commit that goes into SVN, before actually pushing it.

Commit back to the scipy svn repository with git svn dcommit:

git svn dcommit

Note that this will create one commit for each one you have in Git.

If you want to compress things to more compact form, you can use rebase

git rebase -i HASH

where HASH is a commit preceding the one, starting from which you want to compress history. This interactive rebasing allows you e.g. to edit commit messages, reorder commits (may cause conflicts), or squash several commits into a single one.

It may be wise to do create a separate branch for working on this in case you mess up.

Before actually committing, it is also a good idea to check whether you are committing where you think you are committing (with the dry run option of git svn dcommit):

git svn dcommit -n

If you want to view a diff of the changes to be committed, use this script:

#!/bin/bash
if test "$1" = "-r"; then
    # Rebuild git-svn's database
    ODR="$PWD"
    while test "$PWD" != "/"; do
        if test -d .git; then
            rm -rf .git/svn
            break
        fi
        cd ..
    done
    cd "$ODR"
fi
run() {
  git svn dcommit -n 1> /dev/null;
  git svn dcommit -n | { \
      read X; echo "$X"; while read X; do git $X  -M -C --pretty --stat -p; done }
}
run 2>&1| less

Save it somewhere in your $PATH as git-show-dcommit and make it executable. Then, you can do git show-dcommit to view what is to be committed. You can also use it as git show-dcommit -r to rebuild git-svn's SVN database.

Fetching items directly from SVN

You can update your repository directly from SVN:

git svn fetch

It will usually still stay compatible with the SVN mirror even if you do this. There are, however, some corner cases that may arise if you commit merge commits to SVN: then history generated by svn fetch may start to deviate from that in the mirror.