我没有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
处的标准branches
、tags
、trunk
目录结构
将提交从git
存储库复制到project
子版本中继:
-
从Subversion:创建Git存储库
cd /repos git svn clone --stdlayout --revision 1:HEAD --no-minimize-url http://svn/project
-
将
git
存储库添加为远程:cd project git remote add /repos/project.git
-
获取所需的
git
提交。例如,您可以先使用git pull
,然后使用git rebase [commit-id-of-the-subversion-head]
来删除不需要的提交,或者首先使用git cherry-pick
只获取其中的一些提交。 - 当您有想要的提交时,
git svn dcommit
将提交到Subversion
您可以保留两个git
存储库,只需使用git svn rebase
更新/repos/project
,然后再从/repos/project.git
执行其他pull
或cherry-pick
。