简体   繁体   English

配置git-svn

[英]Configuring git-svn

I'm an svn user with a requirement to mirror my svn code to a git repository. 我是一个svn用户,需要将我的svn代码镜像到git存储库。 Users of git will not have access to the svn repository, so the solution cannot rely on checking out the code directly from svn as some kind of external repository. git的用户将无法访问svn存储库,因此解决方案不能依赖于直接从svn检出代码作为某种外部存储库。

I'm trying to use git-svn such that I can make changes in svn, then update and sync them to git. 我正在尝试使用git-svn,以便我可以在svn中进行更改,然后更新并将它们同步到git。

I've cloned the git repo into which I want to sync my svn code, then I do something like: 我已经克隆了我想要同步我的svn代码的​​git repo,然后我做了类似的事情:

git svn clone svn+ssh://path/to/my/code --trunk my_module --prefix mirror/

I can see my svn repo being cloned. 我可以看到我的svn repo被克隆了。 If I try to switch to the trunk branch like this: 如果我尝试像这样切换到trunk分支:

git checkout mirror/trunk

I'm told that I'm in a detached HEAD state (a suitable error message for how I feel right now.) 我被告知我处于一个detached HEAD state (一个适合我现在感觉的错误信息。)

So my question is, how do I get my locally checked out svn code to upload into a remote git repository. 所以我的问题是,如何将我本地检出的svn代码上传到远程git存储库。 And secondly, how would I go about doing periodic updates of that code? 其次,我将如何定期更新该代码?

mirror/trunk is what git calls a remote tracking branch -- you can't commit to it locally, only fetch to update it, so that's why you're seeing the somewhat dramatic "detached HEAD" message. mirror/trunk是git所谓的远程跟踪分支 - 你不能在本地提交它,只能获取更新它,这就是为什么你会看到有些戏剧性的“分离的HEAD”消息。

You likely were already on the local branch that tracks it by default, master , right after the clone. 你可能已经对当地分支 ,默认情况下,跟踪它master ,克隆之后。 To get back, just run git checkout master . 要回来,只需运行git checkout master

To move code from svn into git , first add a remote for the git repository you want your code to end up in: 要将代码从svn移动到git ,首先要为您希望代码最终添加的git存储库添加一个远程

git remote add public git@...

I would recommend creating a new branch for the svn work to live in, so the git developers don't commit to it and complicate things: 我建议为svn工作创建一个新的分支,所以git开发人员不会提交它并使事情复杂化:

git checkout -b svn-work

Then push it out to the remote you just set up: 然后其推出到您刚刚设置的遥控器:

git push public svn-work

To keep the git clone up to date, you'll want to run (manually or by cron): 为了使git clone保持最新,你需要运行(手动或通过cron):

git svn rebase
git push public svn-work

Things get trickier if you want the connection to be bidirectional. 如果您希望连接是双向的,事情会变得棘手。 The command to move work from git to svn is simple enough: 将工作从git移动到svn的命令很简单:

git svn dcommit

... but there are a lot of caveats in terms of what you can push back into svn; ......但是你可以回到svn的内容有很多警告; basically, git users will need to ensure that the history of that branch is kept linear, which is not a trivial thing to accomplish. 基本上,git用户需要确保该分支的历史保持线性,这不是一件容易实现的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM