[英]Shell script to read changes from GIT repo and then commit these changes to SVN
I have no shell scripting experience. 我没有shell脚本编写经验。 I want to create a shell script that will fetch changes from GIT and commit these changes to the SVN repository.
我想创建一个Shell脚本,该脚本将从GIT获取更改并将这些更改提交到SVN存储库。
After searching a lot online and reading this link: Shell script to check git for changes and then loop through changed files? 在网上搜索了大量内容并阅读以下链接后: Shell脚本检查git的更改,然后循环遍历更改的文件?
i could come up with the following... 我可以提出以下...
#!/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
I guess the above will get changes from the GIT repo. 我想以上内容将从GIT存储库中获得更改。 Am I on the right path here?
我在正确的道路上吗? And now in the loop I want to commit the changes obtained from GIT.
现在在循环中,我要提交从GIT获得的更改。
How can this be done ? 如何才能做到这一点 ?
I will be adding this script in Jenkins and it will execute as a post-build action. 我将在Jenkins中添加此脚本,它将作为生成后操作执行。
You'll want to use git-svn
as Ju Liu suggested . 您将按照Ju Liu的建议使用
git-svn
。 Let's say you have the following setup: 假设您有以下设置:
/repos/project.git
. /repos/project.git
。 branches
, tags
, trunk
directory structure at http://svn/project
. branches
, tags
, trunk
目录结构位于http://svn/project
。 To copy commits from the git
repository to the project
Subversion trunk: 要将提交从
git
存储库复制到project
Subversion干线:
Create a Git repository from Subversion: 从Subversion创建一个Git存储库:
cd /repos git svn clone --stdlayout --revision 1:HEAD --no-minimize-url http://svn/project
Add the git
repository as a remote: 将
git
仓库添加为远程仓库:
cd project git remote add /repos/project.git
Get the git
commits you want. 获取所需的
git
commits。 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. 例如,您可以使用
git pull
然后使用git rebase [commit-id-of-the-subversion-head]
来删除不需要的提交,或者使用git cherry-pick
首先只获取其中的一些。
git svn dcommit
to commit to Subversion. git svn dcommit
提交到Subversion。 You can keep both git
repositories, and just update /repos/project
with git svn rebase
before doing additional pull
s or cherry-pick
s from /repos/project.git
. 您可以保留两个
git
存储库,并仅使用git svn rebase
更新/repos/project
,然后再从/repos/project.git
进行其他pull
或cherry-pick
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.