Convert an SVN checkout to use git (git-svn)

假装没事ソ 提交于 2019-12-18 01:28:33

问题


I work with software that is kept in svn for version control. I would like to use git (git-svn) however the software requires lots of setup and configuration before it can be used. There are tools that take care of all of the setup, including checking out all the code via svn.

All the documentation for git-svn (I've been able to find) requires a fresh checkout, using git-svn.

Is there a way to convert an existing svn checkout so it can use git-svn?


回答1:


You could do something like this:

  1. Do a full clone of your SVN tree using git-svn, to a temporary directory. Make sure you use the exact same revision as your existing checkout.
  2. Move the ".git" folder from the top level of the git-svn checkout into the top level of the SVN checkout.
  3. Then you'll either need to tell Git to ignore the ".svn" directories, or you can delete them all.
  4. Delete the git-svn checkout.
  5. There, now you can manipulate your existing files with Git and git-svn.
  6. Do a "git status" and hope that it says there are no changes.



回答2:


No. A git-svn clone converts the entire repository into git. SVN checkouts do not have the entire repository and so cannot be cloned from. This is the primary advantage of switching from SVN or CVS to a distributed system (like git).




回答3:


I assume you probably want to keep the history. However, in case you (or anyone else who stumbles on this page) doesn't need history, you can use the "export" feature as explained here: https://stackoverflow.com/a/419475/2437521.




回答4:


Another way to do this, which does not modify the original Subversion working copy and does not require you to copy it, is using a patch:

  1. Do a full clone of your Subversion tree using git-svn, to a new directory which will be the Git repository. Make sure you use the exact same revision as your existing checkout. You can use git reset --hard :/r<revision> to force it to be the same revision after cloning, where <revision> is the revision that the Subversion working copy is updated to (see this using svn info there).
  2. cd to your Subversion working copy.
  3. Use svn status to make sure all new files are marked with A (or use svn add to add them), and all deleted files are marked with D (or use svn rm to delete them).
  4. Run svn diff >patch.diff to create a patch file.
  5. Copy patch.diff to the top of the Git repository created before.
  6. cd to the top of the Git repository created before.
  7. Run git apply -p0 patch.diff to apply the patch on the working tree of the Git repository.

Now you can go through the changes using git status, and git add/git commit them to save them in your local repository.



来源:https://stackoverflow.com/questions/826865/convert-an-svn-checkout-to-use-git-git-svn

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