user4964330
user4964330

Reputation:

Renaming trunk folder after SVN to Git Migration

I have 30 some projects which I migrated to Git, from SVN.

However, when I browse the folder structure, I still see the trunk folder there in each project. Is there a way to remove this quickly and automatically?

Here is my svn folder structure, note that the repository itself does not have trunk, but the projects do:

--MyRepository
  --Project1
    --trunk
      -- files
  --Project2
    --trunk
      -- files
  --Project3
    --trunk
      -- files
  --Project4
    --trunk
      -- files
  --Project5
    --trunk
      -- files
  -- ..

And this is what I want in my Git repository:

--MyRepository
  --Project1
    -- files
  --Project2
    -- files
  -- ..

Thanks in advance.

PS: I thought I could share the commands which I use to migrate. There it goes:

mkdir gitRepo && cd gitRepo
git svn init http://bla/svn/myRepo --no-metadata
git config svn.authorsfile ../authors.txt
git svn fetch

Upvotes: 1

Views: 1325

Answers (3)

user4964330
user4964330

Reputation:

So, here it goes.

The command which does the magic is:

git filter-branch -f --index-filter \
    'git ls-files -s | sed "s-/trunk/-/-" |
            GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
            git update-index --index-info &&
     mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' af117ec86a30ba6676571cd1f73083c5cfbec0bd..HEAD

note the commit tag before ..HEAD, that should be either second or third earliest commit tag that you should enter. If you enter the first, you get an error.

To find out the commit tag of the earliest commit, simply use:

git log

and scroll down as much as you can, there you will see the earliest commits. Take the second or third. It's done.

Upvotes: 1

kan
kan

Reputation: 28951

If you migrate correctly, then it should be no trunk folder. See --stdlayout of the git svn. So, you have three options:

  1. Redo migration correctly (easiest, but will affect git repo users if any).
  2. Re-carve git history using filter-branch or something similar (should be faster than first one and doesn't need original svn repos, but will affect git repo users if any).
  3. Just move folders and commit (easiest and safest, but the trunk folder will stay in the history forever).

How to migrate repo properly. As I understand you have a svn repo structure like this:

/
/projectA
/projectA/trunk
/projectA/branches/...
/projectB
/projectB/trunk
/projectB/branches/...

So you should do two migrations, creating two git repositories, for each project:

 git svn clone --stdlayout full/svn/repo/url/projectA
 git svn clone --stdlayout full/svn/repo/url/projectB

The thing is - svn doesn't have any idea about trunk and braches, all it understands is a folder. When you migrate to git, you should know your svn repo structure and accordingly map folders to branches.

Upvotes: 1

Sathish Prabhakaran
Sathish Prabhakaran

Reputation: 261

No, you should structurize the folder root as you want at first and then you should map the root. A Proper way of doing.

Upvotes: -1

Related Questions