How to modify git repository to add submodules in

2020-07-25 01:56发布

问题:

I migrated my SVN repository successfully with Tags into Git using git svn-clone. However, git svn-clone does not migrate svn:externals. Hence, I decided to modify branch tree using git filter-branch.

For svn:externals, first I created a separate Git repository for each svn:externals and then I tried using the following, but it didn't work.

$ git filter-branch --tree-filter "git submodule add git@github.com:myAcc/mySubmodule.git mySubmodule" HEAD
Rewrite a013a219e4294d4ee66b323cf1db9c170d90130a (1/4)fatal: working tree '.' already exists.
Clone of 'git@github.com:myAcc/mySubmodule.git' into submodule path 'common' failed
tree filter failed: git submodule add git@github.com:myAcc/mySubmodule.git mySubmodule
rm: cannot remove `c:/myRepo/.git-rewrite/revs': Permission denied
rm: cannot remove directory `c:/myRepo/.git-rewrite': Directory not empty

Any idea how to accomplish this? Thanks a lot in advance.

回答1:

I think you could do it this way, but it may be possible to do it in a cleaner way:

  1. Create temporary empty git repository
  2. Add your svn:externals to it as submodules and commit; note the SHA name of this commit
  3. Go into your old repository
  4. git fetch from the temporary repository
  5. git rebase <SHA of the only commit in the temporary repository>