svn存储库的只读git镜像

Mar*_*llo 15 svn git post-commit

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

eha*_*ost 4

我在一个使用 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"
Run Code Online (Sandbox Code Playgroud)

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

当然,您需要设置一个名为githubusing的遥控器git remote add github [...]。我使用的 git 存储库是一个“裸”存储库(请参阅 参考资料git init --bare)。