I am in the process of moving a project from SVN to GIT. When the project was set up every component of the software was put into its own set of trunk, tags, and branches directories. We want to move from this multiple SVN repository scheme to a single GIT repository.
I believe I have a script that works to clone from SVN into multiple GIT repositories. At least all the history, branches and tags are inside of GIT. There is a problem, the files aren't really in their proper locations so merging them into one repository and keeping the history isn't so easy.
To be more verbose we have a directory structure like:
root
|-->demo
|--> demo1
|-->branches
|-->tags
|-->trunk
-- file 1
-- file 2
|--> demo2
|--> <same as above>
|-->Source
|--> Package A
|--> <same as above>
|--> Package B
|--> <same as above>
The procedure I'm following:
- Create the project directory tree
- git svn clone into each directory
- make all branches local
I have then tried the following:
- git init a new repository
For each of the repositories above
- git remote add -f all the repositories created above
- git merge with the --no-commit --no-ff
- git read-tree with a --prefix= to where the files should go
- git commit that
All the files show up in their proper directories. git log will show all the history for the entire repository taken from SVN. But git log filename only shows the latest commit, so it has lost the link to the main log because everything was moved. Also all the branches still have their files in the base directory so when I do a git checkout the rest of my tree disappears and all that is there are the files that are part of the repository that the branch came from.
I have also tried:
- git mv each file but I got the same result as above
What I think I should be doing is:
For each of the repositories
- git filter-branch using the example in git help filter-branch for changing the sub directories. For instance and example:
~/root/demo/demo1$ git filter-branch --index-filter 'git ls-files -s | sed "s-\t\"*-&root/demo/demo1/-" | GIT_INDEX_FILE=$GIT_INDEX_FILE.new \ git update-index --index-info && mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' HEAD
Rewrite 821c68304e6521b851903463387c1fcccb34958a (1/635)mv: cannot stat ‘root/demo/demo1/.git-rewrite/t/../index.new’: No such file or directory index filter failed: git ls-files -s | sed "s-\t\"*-&software/root/bsp/-" | GIT_INDEX_FILE=$GIT_INDEX_FILE.new \ git update-index --index-info && mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"
It's throwing an error about the .git-rewrite/t/../index.new file not existing.
When I try to do the same operation with two test GIT repositories it works fine. I have tried to clone the repository in hopes that might sort out the problem but it didn't help. So my questions are:
How do you move a GIT repository created from SVN? Am I even creating the GIT repositories from SVN correctly? Is there a better way to grab all these small SVN repositories and merge them into one GIT repository?
Supplementary to that is what does the git update-index and the git filter-branch do specifically in this case? Can I split them up into other steps in my scripts so that I can get around the problem I'm having? I guess what I'm specifically asking is what sets GIT_INDEX_FILE and what does it set it to?
I am running git 1.9.1 if that's any help.