Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"git rebase <branch>" on git svn repo changed remote tracking destination?

Tags:

git

svn

git-svn

I have a git svn repo. I have multiple release branches in here. I was preparing a new release and as part of it, I figured I'd do a "git rebase" from the previous release to pull over any changes that hadn't been merged.

So I set up my branches...

git branch new_release remotes/svn-branches/new_release
git branch old_release remotes/svn-branches/old_release

And then I did the rebase...

git checkout new_release
git rebase old_release
# watch it pull a bunch of commits
git svn dcommit
    Committing to https://svn.mysvn.net/repo/releases/old_release ...

After I did the "svn dcommit" I almost crapped my pants. It was hosing my old release branch in Subversion!

Why did the remote tracking branch change as a result of doing the rebase?

How do I fix the situation I've gotten myself into?

EDIT: Okay, for getting myself out I believe I can do the following: http://svnbook.red-bean.com/en/1.5/svn.branchmerge.basicmerging.html#svn.branchmerge.basicmerging.undo

Since there are only a handful of commits that were on the new_release branch that were pulled to old_release, I can revert them by hand individually on the SVN repo. I'm still confused at what happened here though.

EDITx2: Yep, here are some steps to verify.

  1. Set up two git branches tracking remotely to SVN branches
  2. Check out one of the branches
  3. Run git svn info and observe the URL points to the correct location in SVN
  4. Run git rebase <other_branch>
  5. Run git svn info again and observe the URL changed to point to the other branch location in SVN
like image 816
ashgromnies Avatar asked Dec 19 '12 16:12

ashgromnies


1 Answers

Looks like you've made a common mistake while working with git-svn.

There's no such thing as "tracking branches" in git-svn. It always determines URL of branch to dcommit to by first-parent history until the first commit with "git-svn-id:" signature is met. The URL near this signature is the URL where the commit will be pushed. But note, there's a double check: the URL and revision near the signature is compared with data structures in .git/svn/refs directory and if the URL and revision contradicts them (that is true for rebased commits because rebase doesn't touch those structures), it is not considered. So the old branch URL was the first URL of commit that wasn't rebased.

If you want pure Git experience, you might try SubGit as git-svn replacement. Since 2.0 it allows to create a writable pure Git mirror of your SVN repository, taking care about synchronization and concurrency. Run

$ subgit configure --svn-url <SVNURL> project.git
$ #adjust projectX.git/subgit/{config,authors.txt,passwd} 
$ subgit install project.git
$ git clone project.git project/

After installation you may use it as a normal Git repository. So for you example you run:

$ git checkout new_release
$ git rebase old_release
$ git push origin new_release
like image 198
Dmitry Pavlenko Avatar answered Oct 14 '22 12:10

Dmitry Pavlenko