Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create a new svn branch with git-svn

While working with git-svn, and a 'typical' svn repo /trunk, /branches/..., /tags/... How do I push a local branch to a new branch inside of /branches ?

like image 477
jsharpe Avatar asked Mar 29 '10 14:03

jsharpe


People also ask

How do I create a branch in SVN?

From the git docs: branch Create a branch in the SVN repository. -m, --message Allows to specify the commit message. -t, --tag Create a tag by using the tags_subdir instead of the branches_subdir specified during git svn init. Previous versions of git do not provide a way to create an svn branch. Share.

Can you merge SVN branches in Git?

If the SVN repository has branches or tags, they can be handled the same way trunk is handled. Git svn can be used to create branches, but I wouldn’t recommend using this feature. Git cannot merge SVN branches, so do not merge sync’ed SVN branches in Git.

How does Git SVN clone-s work?

git svn clone -s will then create a branch sub. It will also create new Git commits for r.100 through r.199 and use these as the history of branch sub. Thus there will be two Git commits for each revision from r.100 to r.199 (one

Is your Git master in sync with SVN trunk?

Now that the remote Git master is in sync with SVN trunk, let’s go through the steps as if we don’t have a local Git repository, i.e., the perspective of your teammates. Fortunately, these steps are similar to the initial setup, but they must be followed each time the remote Git repository is cloned.


1 Answers

Say we have a skeleton Subversion repository with empty trunk/, branches/, and tags/:

/tmp$ git svn clone -s file:///tmp/svn-repo/ git-svn-repo
Initialized empty Git repository in /tmp/git-svn-repo/.git/
r1 = 80bdcfc0cf248b74b914a1b5f99ab89fb4e31b6c (refs/remotes/trunk)
Checked out HEAD:
  file:///tmp/svn-repo/trunk r1

/tmp$ cd git-svn-repo/

/tmp/git-svn-repo$ git svn branch my-branch
Copying file:///tmp/svn-repo/trunk at r1 to file:///tmp/svn-repo/branches/my-branch...
Found possible branch point: file:///tmp/svn-repo/trunk => file:///tmp/svn-repo/branches/my-branch, 1
Found branch parent: (refs/remotes/my-branch) 80bdcfc0cf248b74b914a1b5f99ab89fb4e31b6c
Following parent with do_switch
Successfully followed parent
r2 = 56150bbd9d3aec94972ff46d030e30ec726595ab (refs/remotes/my-branch)

The explanation below will switch back-and-forth between two views of the same repository, a Subversion working copy of the entire repo (not just trunk) and a git-svn clone. For clarity, each shell prompt's prefix will indicate the current directory.

On the svn side, you'll now see

/tmp/svn-repo-wc$ svn up
A    branches/my-branch
Updated to revision 2.

You'll also see the new branch on the git side:

/tmp/git-svn-repo$ git branch -r
  my-branch
  trunk

To commit to the newly created branch, first switch to it:

/tmp/git-svn-repo$ git reset --hard remotes/my-branch
HEAD is now at 2c9bef2 Create branch my-branch

Next, we'll create a dummy git commit

/tmp/git-svn-repo$ touch on-my-branch
/tmp/git-svn-repo$ git add on-my-branch
/tmp/git-svn-repo$ git commit -m 'First commit to my-branch'
[master b94a0eb] First commit to my-branch
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 on-my-branch

and finally send it to Subversion:

/tmp/git-svn-repo$ git svn dcommit
Committing to file:///tmp/svn-repo/branches/my-branch ...
    A   on-my-branch
Committed r3
    A   on-my-branch
r3 = d3c5ba3e03e5cdee96f470ff4c9898eb7c523ed8 (refs/remotes/my-branch)
No changes between current HEAD and refs/remotes/my-branch
Resetting to the latest refs/remotes/my-branch

The Subversion working-copy gives us confirmation:

/tmp/svn-repo-wc$ svn up
A    branches/my-branch/on-my-branch
Updated to revision 3.
like image 120
Greg Bacon Avatar answered Sep 21 '22 14:09

Greg Bacon