【问题标题】:update svn repo weekly with changes from a git repository with losing history每周更新 svn 存储库,使用来自 git 存储库的更改并丢失历史记录
【发布时间】:2012-10-27 09:17:49
【问题描述】:

我有一个 git 存储库,它是我的开发存储库。我需要每周将所有更改上传到 svn 存储库 - 但我不想公开我的 git-commit-history。换句话说:我明确想要丢失历史。给定一周内 git 存储库中的所有更改都需要压缩到一个 svn 提交。

以一周为例:

Git:

commit 1 "fixed y"
commit 2 "added feature x"
commit 3 "foo"
commit 4 "fixed n"

SVN:

commit 1 "changes from this week"

理想情况下,它应该由通过 cron 作业自动启动的小型 shell 或 python 脚本来完成。

我有以下变量:

LOCAL_PATH=/tmp/git-svn-bridge/
GIT_DIR=git_repo
SVN_DIR=svn_repo

GIT_REPO_URL=git://git@my_git_server
GIT_REPO_NAME=my_git_repo
GIT_REPO_BRANCH=master

SVN_REPO_URL=svn://my_svn_server
SVN_USER=FIXME
SVN_PASS=FIXME

有什么想法吗?

感谢阅读!

【问题讨论】:

    标签: git svn shell cron commit


    【解决方案1】:

    这是一般的想法 - 使用 git archive 导出,然后使用 rsync -a --delete 更新 svn 工作副本。类似的东西:

    #!/bin/bash -xue
    
    gitdir='/path/to/git/repo-clone/'  
    gitbranch='master'
    
    svncodir='/path/to/svn/svn-checkout' 
    svnrepo='file:///tmp/svnrepo'  # no trailing slash
    
    # if svn checkout doesn't exit
    [[ ! -d $svncodir ]] && svn co $svnrepo $svncodir
    
    # if svn checkout is pointing to a different repo
    if svn info $svncodir | grep -qF "URL: $svnrepo"; then
      rm -rf $svncodir
      svn co $svnrepo $svncodir
    fi
    
    tmpdest=$(mktemp -d)
    git --git-dir $gitdir/.git archive $gitbranch | tar -x -C $tmpdest
    
    cd $svncodir
    svn update
    
    # sync our temporary dir with the current svn checkout
    rsync -av --delete --force --exclude '.svn' $tmpdest/ .
    rm -rf $tmpdest/
    
    # svn add new or modified files
    svn add . --force --no-ignore
    
    # remove missing ones (whitespace safe, unless you have
    # files with 5 spaces in them)
    svn status | awk -F' {5,}' '/!/ {print $2}' | xargs -I'{}' svn rm '{}'
    
    svn status 
    svn commit -m "changes from this week"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多