Silence is Foo Mental notes on Ruby, Git, Rails and whatever geeky thing

9Oct/09Off

OMFG, do I really have to get back to SVN??? Part 2

In the first part of this post we started to use git to commit to/update from a SVN server, but we didn't touch one of the more interesting parts of Git: branching

Why would I want to use the git branching capabilities?

  1. because you can't create local branches in SVN
  2. because you can't commit locally in SVN

In this post we'll see how to work with SVN and Git branches.

NOTE: branches in Git are pointers to commits, branches in SVN are copies of files

first, let's create a branch in our SVN server:

$ svn copy trunk branches/my_new_svn_branch
     A         branches/my_new_svn_branch
$ svn commit -m "we've got a new svn branch"
     Adding         branches/my_new_svn_branch
     Committed revision 8.

let's see our local and remote branches in Git

$ git branch -r //remote branches
   trunk // <---tracked by master local branch
   my_new_branch
   another_branch

$ git branch -l //local branches
  * master // <-- tracking the trunk remote branch

now, let's update our git repository

$ git svn rebase //this command will only fetch changes to files
    A    branches/my_new_svn_branch/README
    r8 = 635ea8cd541e29f12e86f439fb86787e6dc19f43 (git-svn)
    First, rewinding head to replay your work on top of it...
    Fast-forwarded master to refs/remotes/git-svn.

we must use the "fetch" command

$ git svn fetch (or rebase --all) //it'll fetch changes and detect svn branches

Found possible branch point: https://svn_repo_url/trunk => https://svn_repo_url/branches/my_new_svn_branch
Found branch parent: (my_new_svn_branch) 06a39b6e3b932b9fe5a7bfd0c7e4c57c9b14dee0
Following parent with do_switch
 M    README
Successfully followed parent
r8 = 1a7df4c58fe71bb864cf6ecf5c67133ef5ecece4 (my_new_svn_branch)

at this point, if you look at the remote branches, you'll find the new svn branch (my_new_svn_branch)

$ git branch -r
   trunk
   my_new_branch
   another_branch
   my_new_svn_branch // <--- here is

ok, let's say we want to fix a bug in the my_new_svn_branch branch, so, we crate a new local branch  (thanks Git):

$ git checkout -b bug_killer my_new_svn_branch

is that truth? yes, it is, let's see

$ git branch -l
  master
  *bug_killer // <-- here is

now, the bug_killer local branch is tracking the my_new_svn_branch remote branch

now we need to commit something

$ vim README //we modify the file
$ git commit -m "modification 1"

$ git checkout master //let's go to the master branch

$ vim README //we modify the file in the master branch, why not?
$ git commit -m "modification 2"

$ git checkout bug_killer //get back to bug_killer branch

$ vim YET_ANOTHER //we create a new file
$ git add YET_ANOTHER
$ git commit -m "I added a file"

at this point our bug_killer local branch is ahead of the my_new_svn_branch remote branch

and the master local branch is ahead of the trunk remote branch

so, we need to commit to the SVN server

$ git checkout bug_killer

$ git svn rebase //update the my_new_svn_branch branch
$ git svn dcommit //this will update the my_new_svn_branch directory

$ git checkout master

$ git svn rebase //update the trunk branch
$ git svn dcommit //this will update the trunk directory

$ git branch -d bug_fix //delete the bug_fix local branch, we don't need it anymore

and then we'll have three new commits in our SVN server


$ svn update

Creating a SVN branch through Git

well, I've created a branch in SVN through a SVN client and then we updated our Git repository and we got the new svn branch, but, what about create a svn branch through

$ git svn branch branch_name -m "commit message"
Copying https://svn_repo_url/trunk at r19 to https://svn_repo_url/branches/branch_3...

Found possible branch point: https://svn_repo_url/trunk => https://svn_repo_url/branches/branch_3, 19
Found branch parent: (branch_3) 06a39b6e3b932b9fe5a7bfd0c7e4c57c9b14dee0
Following parent with do_switch
Successfully followed parent
r26 = f27899a85d5328e3d038faf4b1e9f9eab2434fff (branch_3)

how another developer would see this?

$ svn update
A    branches/branch_3
A    branches/branch_3/YET_ANOTHER
A    branches/branch_3/README
Updated to revision 26.

very good!

About raf

Ruby Developer
Filed under: git Comments Off
Comments (0) Trackbacks (0)

Sorry, the comment form is closed at this time.

Trackbacks are disabled.