首页 文章

svn存储库的只读git镜像

提问于
浏览
15

设置现有svn存储库的只读git镜像的最佳方法是什么,并设置post-commit钩子,这样每当有人提交svn时,git镜像会自动更新?主要是,我想在服务器上运行一次git-svn clone,然后让人们从git中检出而不必git-svn自己克隆整个svn存储库 .

2 回答

  • 2

    我在使用SVN的项目上执行此操作(推送到github上的公共存储库) . 我没有SVN提交挂钩,但这是在cron作业上:

    #!/bin/bash
    
    repo=/path/to/my-mirror.git
    lockfile="$repo/cron-lock"
    
    if ! lockfile -r1 "$lockfile";then
            exit 1
    fi
    
    export GIT_DIR=$repo
    # update refs/remotes/git-svn:
    git svn fetch -q
    # make 'master' match the git-svn branch:
    git fetch "$repo" refs/remotes/git-svn:refs/heads/master
    # publish to github
    git push github master
    
    rm -f "$lockfile"
    

    如果从SVN提交挂钩而不是cron作业触发它,它应该可以工作 .

    当然,您需要使用 git remote add github [...] 设置一个名为 github 的遥控器 . 我正在使用的git存储库是一个"bare"存储库(请参阅 git init --bare ) .

  • 4

    设置Svn / Git镜像(可写)的最佳方法是使用SubGit - 这是专门为此任务开发的工具 . 免责声明:我是这个工具的开发者 .

相关问题