The story of Git, Git-Submodule and a SVN server

孤街浪徒 提交于 2019-12-23 15:56:38

问题


First of all i want to show you my project setup, I've two projects

  • Project X: Cloned from a remote svn server with git svn clone
  • Project y: Located on GitHub

Project X references Project y as git submodule:

-- Project X
  -- src/
    -- myCode1/
    -- *Project y Submodule*
    -- myCode2/
  -- .git/
  -- ...

Now I want to "push" my local done commits to the remote svn server with git svn dcommit.
Can anyone explain me the correct workflow for that project structure?


If I want to update my local git repo from the svn server I run git svn rebase and get the following:

error: The following untracked working tree files would be overwritten by checkout

Git lists all files of the submodule, but I tracked the submodule already in my local repo.
Any ideas or suggestions?


回答1:


From my experience git-svn doesn't work with Git submodules, mostly because of the way it sends changes to SVN: if you debug it a bit, you'll discover that it sends delta to SVN (so such pure Git concepts like submodule is not translated), then fetches just sent revision back (hence this revision doesn't contain submodules) and after all replaces just sent commit with fetched version (so the submodule will be lost in this process in the best case, though from my experience it just fails earlier). So if you can just have an untracked directory 'Project y Submodule' and manage it manually, not as submodule.

Alternatively you can try SubGit as git-svn replacement. Since 2.0 EAP it allows to create a Git mirror for a remote SVN repository.

$ subgit configure --svn-url http://svnhost/svnpath/projectX projectX.git
$ #adjust projectX.git/subgit/{config,authors.txt,passwd} and, if possible, enable rev-propchange-hook in SVN repository
$ subgit install projectX.git

After that you can clone projectX.git and work with it as with usual Git repository, the synchronization will be performed automatically. So after installation you add Project y Submodule as normal Git submodule of projectX.git.

$ git submodule add git://github.com/.../projectY.git projectY
$ git commit -m "Added projectY as submodule"
$ git push

The only thing to do is to make sure that there's no file or directory with such name in SVN, or it will overwrite the submodule.



来源:https://stackoverflow.com/questions/13954907/the-story-of-git-git-submodule-and-a-svn-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!