如何将 Google Code 上的 SVN 代码仓库迁移到 GitHub 上的 git 代码仓库?

11

我在将托管在code.google的SVN版本库切换到GitHub上的git版本库方面遇到了困难。具体来说:

  1. 如何在保留修订历史记录的同时,从SVN更改code.google上的代码为GIT?
  2. 如何在保留修订历史记录的同时,从SVN更改code.google上的wiki为GIT?
  3. 如何将我的GIT版本库从code.google迁移到GitHub?
  4. 如何在仍使用GitHub作为主要版本库的情况下,使两个版本库彼此同步?
2个回答

9

变量:

  • $project 是您的项目名称
  • $username 是您在github上的用户名

这假设您的$project名称与github上的名称相同,并且您已经初始化了github存储库。

另外,如果您的code.google存储库已经是GIT,则可以跳过步骤4。

  1. Convert project from SVN to GIT. This is as easy as going into the Administration->Source tab and change it from SVN to GIT. By the way, the svn is still available after you do this; so don't worry about a complete code loss.

  2. Convert source from code.google SVN to code.google GIT (keeping history)

    git svn clone --stdlayout https://$project.googlecode.com/svn $project
    cd $project
    git remote add googlecode https://code.google.com/p/$project
    git push --all googlecode
    cd ..
    
  3. Convert wiki from google SVN to google GIT (keeping history)

    git svn clone https://$project.googlecode.com/svn/wiki $project.wiki
    cd $project.wiki/
    git remote add googlecode https://code.google.com/p/$project.wiki
    git push --all googlecode
    cd ..
    
  4. Get new git repo from github

    mkdir github
    cd github/
    git clone https://code.google.com/p/$project.git
    cd $project/
    
  5. Get source from code.google GIT to local github clone

    git remote set-url origin https://github.com/$username/$project.git
    git pull
    
  6. Push source from local clone to github

    git push origin master
    
  7. Tell your local clone to push commits to github AND code.google

    git remote set-url --add origin https://$project.googlecode.com/git
    
  8. Test pushing commits to both github and code.google

    touch test.txt
    git add test.txt
    git commit -m "Testing repo replication" test.txt
    git push
    
现在,无论您对本地克隆进行何种更改,它都会将这些更改推送到两个存储库。请注意:如果您在另一个位置(例如不同的计算机)再次克隆,则必须再次重复第6步。

0

现在Google Code上有一个导出功能 - 前往您的项目的Google Code页面,即code.google.com/p/yourproject,然后您应该会看到一个按钮'Export to GitHub',它将在几个步骤内完成(注意:您需要使用您的GitHub帐户进行授权)。

请注意,您可以为任何项目执行此操作,而不仅仅是您自己的项目。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接