1

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
  • 1
    Would be easier if you show what folder layout you have in svn and what you want to have in git. – kan May 12 '16 at 14:48
  • I updated it now, check again please. Thanks a lot. –  May 12 '16 at 14:54

3 Answers3

1

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.

kan
  • 28,279
  • 7
  • 71
  • 101
  • My SVN repository itself does not have `trunk`, but each project has. So when I use `--stdlayout`, it does not work, simply copies nothing. –  May 12 '16 at 13:52
  • That git svn clone command creates the project as a git repository itself, which is not what I am asking for. There has to be 1 repository with 1 .git folder, and 30 projects. –  May 12 '16 at 14:20
  • @frageDE If you have folders in svn, they will become folders in git. `trunk` just a folder name, nothing special. What's wrong about it? Git just keeps original layout. Do you want to change the layout? If so, follow option 2. – kan May 12 '16 at 14:22
  • I don't want 30 Git repositories, I want 1 Git repository with 30 projects in it. If I use the command you gave, it would create 30 Git repositories, each having .git folder in it. This is not what I want. There has to one .git folder in the root, along with 30 projects next to it. Maybe editing the config file under that .git is the solution. –  May 12 '16 at 14:25
  • @frageDE "Option 2" is `filter-branch`, which is about single git repo. – kan May 12 '16 at 14:41
  • Can you direct me to a reasonable tutorial on the matter? –  May 12 '16 at 14:48
  • @frageDE You could start with http://stackoverflow.com/questions/3142419/how-can-i-move-a-directory-in-a-git-repo-for-all-commits as I see you should use `--tree-filter` and craft a command which moves files around as you want. Be aware - after the filter-branch `git svn` syncing could be broken, you cannot dcommit/fetch anymore. – kan May 12 '16 at 15:05
1

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.

-1

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

  • Well, I use `git svn init URL --no-metadata --stdlayout` and then `git svn fetch`, but it does not work. Care to elaborate what you mean by "proper"? –  May 12 '16 at 13:59