How can I change the Prefix Mapping in a Git-Svn Repository?
Asked Answered
B

2

10

I've created a Git Clone of a SVN repository using git-svn. When doing this I specified the --prefix option to prefix my remote branches. I now want to get rid of this prefix.

Is there a way to update or remove the prefix without re-cloning the repository?

Essentially I did the initial clone using --prefix=Project so I ended up with Project/trunk and Project/feature-branch as my remote tracking branches. What I want is to have the trunk just be called trunk and the feature-branch be called svn/feature-branch.

Bowdlerize answered 13/2, 2011 at 19:36 Comment(2)
There is a duplicate question which is answered.Urethroscope
Warning: with git 2.0+ (April 2014), having just 'trunk' (without prefix) might not work anymore. See my answer belowMosesmosey
M
3

Note: the current solution might not work anymore with git 2.0+ (April 2014)

See commit fe191fc by Johan Herland (jherland), which highlight the fact you now are supposed to have a prefix (and not have a svn branch without prefix like 'trunk'):

Git 2.0: git svn: Set default --prefix='origin/' if --prefix is not given

Having no prefix by default was problematic:

git-svn by default puts its Subversion-tracking refs directly in refs/remotes/*.
This runs counter to Git's convention of using refs/remotes/$remote/* for storing remote-tracking branches.

Furthermore, combining git-svn with regular git remotes run the risk of clobbering refs under refs/remotes (e.g. if you have a git remote called "tags" with a "v1" branch, it will overlap with the git-svn's tracking branch for the "v1" tag from Subversion.

Mosesmosey answered 12/7, 2014 at 15:14 Comment(0)
B
9

I've done the following which appears to have worked.

In .git/config I updated the fetch, branches and tags settings to update the local refs. It was:

[svn-remote "svn"]
        url = http://subversion/......
        fetch = trunk:refs/remotes/Project/trunk
        branches = branches/*:refs/remotes/Project/*
        tags = tags/*:refs/remotes/Project/tags/*

Which I changed to

[svn-remote "svn"]
        url = http://subversion/......
        fetch = trunk:refs/remotes/trunk
        branches = branches/*:refs/remotes/svn/*
        tags = tags/*:refs/remotes/svn/tags/*

The within .git/refs/remotes I moved trunk out of the Project folder and the remaining refs within Project into a new folder called svn. The structure was:

  • remotes
    • Project
      • trunk
      • feature-branch

Which I changed to:

  • remotes
    • trunk
    • svn
      • feature-branch

I also performed the same restructuring of folders within .git/svn/refs/remotes/.

Finally I triggered a git svn fetch. I had to specify the -r argument to limit to the same start revision that I used for my initial clone, but it doesn't appear to have re-fetched the old revisions.

Bowdlerize answered 13/2, 2011 at 20:58 Comment(0)
M
3

Note: the current solution might not work anymore with git 2.0+ (April 2014)

See commit fe191fc by Johan Herland (jherland), which highlight the fact you now are supposed to have a prefix (and not have a svn branch without prefix like 'trunk'):

Git 2.0: git svn: Set default --prefix='origin/' if --prefix is not given

Having no prefix by default was problematic:

git-svn by default puts its Subversion-tracking refs directly in refs/remotes/*.
This runs counter to Git's convention of using refs/remotes/$remote/* for storing remote-tracking branches.

Furthermore, combining git-svn with regular git remotes run the risk of clobbering refs under refs/remotes (e.g. if you have a git remote called "tags" with a "v1" branch, it will overlap with the git-svn's tracking branch for the "v1" tag from Subversion.

Mosesmosey answered 12/7, 2014 at 15:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.