Ruby On Rails has a Subversion repository with over 7500 commits at the time of writing. In this article I show how you can use Git to have a full local copy of the repository in 9MB, and use it to track upstream changes.
In a subsequent article I will show you how to use such a repository to easily maintain Rails patches for the six months it takes you to get them accepted into Core (wink).
Background
Git is a revision control system that is distributed, which means that every developer using Git gets to be the ruling dictator of his own distinct code repository. With a distributed RCS, a central “master” repository is an optional result of a consensus decision, and not a technical requirement.
Having a full local repository lets you work off-line, branch and merge freely, and check in regularly without being a project member.
Mirroring subversion repositories: git-svn
Git ships with a nifty tool called git-svn, which can pull and push
changesets between a subversion repository and a git repository,
maintaining tag, branch and author information.
After reading a helpful article I used git-svn to make a mirror of the Rails subversion repository. That step took many hours, so I’ve set up my mirror to update itself regularly throughout the day, and published it at the following Git URL:
1
| |
More on how to use that URL later.
What you will need
Make sure you have git installed, with svn support. (To follow
this article, you don’t need the svn support, but you’ll no doubt
want to play with git-svn yourself.) In most Linuxes, the package
to install is called “git-core”. On a Mac, if you value your time you
will use the MacPorts package
with ‘svn’ variant enabled:
1
| |
Make a local clone of the repository
You can clone my Git mirror of the Rails repository using git-clone:
1 2 3 4 5 6 7 8 9 10 11 12 | |
The newly-created rails directory contains every changeset in
Rails’ history, all stored in only 9.2MB of packed Git data:
1 2 | |
This magic is possible due to Git’s delta compression. Note that a
plain vendor/rails directory alone weighs in at over 8MB.
Here are all the branches:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | |
Note that the default branch is master, which corresponds to origin/trunk - Rails “edge”.
You can trivially switch the working copy in the current directory to another branch, such as the Rails stable branch:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |
Note the embedded subversion revision, @4750.
You can browse the history of the current branch using the gitk GUI.
Keeping your mirror up to date
You’ll want to periodically pull new changes from the Rails repository into your local repository. Use ‘git-pull’ for this:
1 2 3 4 5 6 7 8 9 10 11 12 | |
Making changes locally
With a little git knowledge, you can commit changes into your local repository, getting git to do the magic of merging upstream changes.
If you want to contribute patches back to Rails, you can use git to maintain them; git can regenerate your patches automatically as the surrounding Rails code changes. A follow-up article on this site will describe how to do this.
Further reading
- Git documentation
- This site – why not subscribe to future articles?
Update: I’ve set up gitweb, so you can browse the Rails git mirror here.
Further update: my mirror will be discontinued now that Rails development has switched to Git