gitsvngit-svntrunk

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

Solution

  • 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.