0

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

在网上搜索了很多并阅读了这个链接: Shell script to check git for changes and then loop through changed files?

我可以想出以下...

#!/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 中添加此脚本,它将作为构建后操作执行。

4

1 回答 1

0

You'll want to use git-svn as Ju Liu suggested. Let's say you have the following setup:

  • Git repository at /repos/project.git.
  • Standard branches, tags, trunk directory structure at http://svn/project.

To copy commits from the git repository to the project Subversion trunk:

  1. Create a Git repository from Subversion:

    cd /repos
    git svn clone --stdlayout --revision 1:HEAD --no-minimize-url http://svn/project
    
  2. Add the git repository as a remote:

    cd project
    git remote add /repos/project.git
    
  3. Get the git commits you want. You can for example git pull and then git rebase [commit-id-of-the-subversion-head] to remove unwanted commits, or use git cherry-pick to get only some of them in the first place.

  4. When you have the commits you want, git svn dcommit to commit to Subversion.

You can keep both git repositories, and just update /repos/project with git svn rebase before doing additional pulls or cherry-picks from /repos/project.git.

于 2013-06-26T07:30:16.387 回答