Shell脚本从GIT repo读取更改,然后将这些更改提交给SVN



我没有shell脚本编写经验。我想创建一个shell脚本,从GIT中获取更改并将这些更改提交到SVN存储库。

在网上搜索了很多并阅读了这个链接之后:Shell脚本检查git是否有更改,然后在更改的文件中循环?

我可以想出以下。。。

#!/bin/sh
#checks if there are any changes
if ! git --git-dir="/dir/.git" diff --quiet
then
    # do stuff...
    git --git-dir="/dir/.git" diff-tree ORIG_HEAD.. | 
    while read srcmode dstmode srcsha dstsha status srcfile dstfile
    do
        # do something with $srcfile and $dstfile
    done
fi

我想以上内容将从GIT回购中得到改变。我走的路对吗?现在在循环中,我想提交从GIT获得的更改。

如何做到这一点?

我将在Jenkins中添加这个脚本,它将作为构建后的操作执行。

您将希望按照Ju Liu的建议使用git-svn。假设您有以下设置:

  • 位于/repos/project.git的Git存储库
  • http://svn/project处的标准branchestagstrunk目录结构

将提交从git存储库复制到project子版本中继:

  1. 从Subversion:创建Git存储库

    cd /repos
    git svn clone --stdlayout --revision 1:HEAD --no-minimize-url http://svn/project
    
  2. git存储库添加为远程:

    cd project
    git remote add /repos/project.git
    
  3. 获取所需的git提交。例如,您可以先使用git pull,然后使用git rebase [commit-id-of-the-subversion-head]来删除不需要的提交,或者首先使用git cherry-pick只获取其中的一些提交。

  4. 当您有想要的提交时,git svn dcommit将提交到Subversion

您可以保留两个git存储库,只需使用git svn rebase更新/repos/project,然后再从/repos/project.git执行其他pullcherry-pick

最新更新