Track your changes to an open-source project with git: Difference between revisions

From Bitpost wiki
No edit summary
No edit summary
Line 16: Line 16:
Another basic source control requirement, and we're done.   
Another basic source control requirement, and we're done.   


But <strong>try</strong> to meet this set of requirements with CVS or subversion (SVN).  No longer simple.  Enter git.
But <strong>try</strong> to meet this set of requirements with CVS or subversion (SVN).  No longer simple.  Enter git.  It was born to do this job.  If you're with me so far, and it sounds like we're on the right track, I promise you: step through the rest of this guide and you'll be happy you did.  Let's get to it.


== Setup ==
== Setup ==
Line 22: Line 22:
NOTE: I'm going to use mythtv in this example, because that's what I wanted to work on.
NOTE: I'm going to use mythtv in this example, because that's what I wanted to work on.


Create a local git repository of the project's subversion repository, using git-svn.  There are two ways to do this.  If you do not specify a SVN revision number, git will grab the entire history of the project as it is available in the SVN repo.  WARNING: this may be HUGE for older bigger projects!
Create a local git repository of the project's subversion repository, using git-svn.  There are two ways to do this.  If you do not specify a svn revision number, git will grab the entire history of the project as it is available in the svn repo.  WARNING: this may be HUGE for older bigger projects!
  git-svn clone http://svn.mythtv.org/svn/trunk/mythtv mythtv
  git svn clone http://svn.mythtv.org/svn/trunk/mythtv mythtv
If you specify a revision number, git will grab just that version, and then we can grab all changes after that version, too.  It's probably worth digging into the project history to find a reasonable revision number.
If you specify a revision number, git will grab just that version, and then we can grab all changes after that version, too.  It's probably worth digging into the project history to find a reasonable revision number.
  git-svn clone -r15502 http://svn.mythtv.org/svn/trunk/mythtv mythtv
  git svn clone -r15502 http://svn.mythtv.org/svn/trunk/mythtv mythtv
We now have a repo of the project under git control.  Simple, eh?
We now have a repo of the project under git control.  Simple, eh? git uses branches, and named our svn grab the "master" branch in this repo.  See the list of branches:
git branch
Now we can easily update our master branch with the latest svn commits at any time.  Do this now to make sure you're completely up-to-date:
git svn rebase
Now we create a branch of our own, from the SVN base.  git loves branches!
git checkout -b mybranch
git branch
 
 
 




tbc...
tbc...

Revision as of 17:26, 28 January 2008

Here are quick and easy steps to track your changes to an open-source project.

Once you get a handle on git, you'll find it very powerful. But getting started can be the biggest challenge. Distributed source control requires a different way of thinking than using a central repository. Use this to get past the first hurdles.

Requirements

Before you can start making changes to a project, you should get the code and make sure you can compile and run it. In this guide, we assume that the project is currently under SVN control. Check out a copy and get it up and running.

The next set of requirements is pretty simple:

  • I need my own branch off of the svn branch.
  • I need the ability to overlay the latest svn changes, over time, on top of changes in my branch.

Notice how simple this is - we're not even asking to commit anything yet. These are fundamental requirements that any developer on a non-trivial open-source project would have. You need to do this if you are going to bang on an open-source project.

Now let's add one more requirement. I'm going to have this code on at least three different machines, so I need to be able to have a common repository for my changes.

  • ability to work from several locations, pushing/pulling my changes to a central repo

Another basic source control requirement, and we're done.

But try to meet this set of requirements with CVS or subversion (SVN). No longer simple. Enter git. It was born to do this job. If you're with me so far, and it sounds like we're on the right track, I promise you: step through the rest of this guide and you'll be happy you did. Let's get to it.

Setup

NOTE: I'm going to use mythtv in this example, because that's what I wanted to work on.

Create a local git repository of the project's subversion repository, using git-svn. There are two ways to do this. If you do not specify a svn revision number, git will grab the entire history of the project as it is available in the svn repo. WARNING: this may be HUGE for older bigger projects!

git svn clone http://svn.mythtv.org/svn/trunk/mythtv mythtv

If you specify a revision number, git will grab just that version, and then we can grab all changes after that version, too. It's probably worth digging into the project history to find a reasonable revision number.

git svn clone -r15502 http://svn.mythtv.org/svn/trunk/mythtv mythtv

We now have a repo of the project under git control. Simple, eh? git uses branches, and named our svn grab the "master" branch in this repo. See the list of branches:

git branch

Now we can easily update our master branch with the latest svn commits at any time. Do this now to make sure you're completely up-to-date:

git svn rebase

Now we create a branch of our own, from the SVN base. git loves branches!

git checkout -b mybranch
git branch



tbc...