我如何使用两个SVN项目和相应的git-svn分支与一个工作目录? [英] How can I use two SVN projects and corresponding git-svn branches with a single working directory?

查看:126
本文介绍了我如何使用两个SVN项目和相应的git-svn分支与一个工作目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



任何人都可以为我推荐一款适用于某种情况的工作流程类似于以下内容:


  • 1 SVN回购,包含多个项目

  • 1个工作副本src



ideea是在src中,我需要检出项目A或有时项目B.两个项目都有几个分支。 / p>

现在,我已经为SVN回购制作了2个git克隆,每个项目一个。 (我会首选--bare repos,但它不适用于 git svn clone

然后,我在src中创建了一个git repo,并且 git remote add projA ..a_repo_git git remote add projB ..b_repo_git $ b $ p现在,我可以使用



现在麻烦..




  • 我怎样才能进入 srcprojA / projB中的任何分支?

  • 如何修改它们,然后能够将它们推回(首先到git_repos或直接到SVN回购站点)?

  • 这个工作流程是否正常,或者您有更好的主意?


I在src中尝试过: git checkout --track -b work_branch projA branch_in_A
并且在一些fetch操作完成之后,我设法得到了这些东西。但之后,我遇到了问题,将它推回到 a_repo_git ,然后再转到SVN。这主要是试验和错误。


我不得不承认,我仍然在远程分支上遇到问题! (当我必须使用 origin local_branch:origin_branch origin origin_branch:local_branch 时,或 origin origin_branch origin / origin_branch !回到Git手册获取更多阅读内容。)

解决方案

我没有更新这个问题,因为在过去的几天里,我可以在帮助下工作得非常好,我的新回购:)



这是我最后做的:

初始化两个SVN回购同一个目录。 (我不能在这个时间rember,但可能在同一个目录中完成git init之前:

 
mkdir src && cd src
(不知道这个:git init)
git svn init --stdlayout --prefix = projA / -RprojA file:/// path / to / svn / repo / A
git svn init --stdlayout --prefix = projB / -RprojB file:/// path / to / svn / repo / B

--stdlayout表示SVN回购是标准格式,主干,分支和标签处于同一级别。



--prefix用于分支名称,当我们做git branch -a时,项目A的所有SVN分支都有前缀projA(例如:projA / branch_name_of_A),同样的事情也适用于B.



-R选项在git仓库中设置SVN仓库的名称(这是我们在引用SVN仓库/项目时使用的名称) p>

在这种情况下,file:/// path是SVN回购的路径,以及回购库中的项目。我使用了平面文件回购,没有服务器。对于SVN服务器,我确信它也可以与http://一起工作。

在这一步之后,出于好奇,我查看了src / .git / config文件。上面的两个命令创建了几个svn-remote部分,每个项目一个(-R选项)和一个名为svn的通用部分。我修改了条目,因此只会引用项目。每个引用都包含回购路径(提取)和标签/分支/主干的条目。如果你看看这个文件,你就会明白需要改变什么。



在此之后,我使用

获取每个项目的内容。

 
git svn fetch projA#项目的内容下载的仓库
git svn fetch projB#项目B仓库的内容被下载

现在,runniggit branch -a显示了两个仓库中的所有分支和主分支(本地)。 git branch -r没有显示任何分支;可能是因为它们是svn-remote而不是remote。

当前的主分支指向第二个项目的主干。我决定摆脱它,因为从一个项目切换到另一个时会导致问题。



我创建了两个新的分支来指向然后删除master分支:

 
git checkout -b master_project_A projA / trunk
git checkout - b master_project_B projB / trunk
git分支-D master

现在,对于工作流程;在项目A上工作:

 
git checkout master_project_A #switch to project A
git svn rebase #check for SVN repo
git checkout -b work_on_A master_project_A#从项目主人开始创建一个分支A

在work_on_A上工作的工作;提交等

git checkout master_project_A #go回到项目的主人A
git svn rebase#再次检查SVN回购的任何更新
git checkout work_on_A #go回到工作分支
git rebase master_project_A#更新分支,其中包含项目主人的任何更改A
git checkout master_project_A #go返回项目主人A
git合并work_on_A #merge给项目A来自工作分支
的更改git svn dcommit #commit更改为主干中的SVN回购,因为master_project_A指向其中继

如果我想从SVN签出现有的分支,我可以这样做:

 
git checkout -b work_on_branch projA / branch_name

工作工作

git svn rebase #update projA / branch_name的任何更改
git svn dcommit #commit更新回SVN中的分支回购

对于项目BI,可以做同样的事情。最后,我可以将项目A或B的内容放在同一个目录src中,并且可以从同一个git仓库访问SVN仓库中的两个项目! :D



我还没有弄清楚如何创建本地分支,然后将其推送到SVN回购 - 我很接近,但它没有奏效。

另外,知道命令reset(git reset --hard projPrefix / branch)可能会很有用,但是我用它打破了一些东西,所以我希望这可以帮助别人!



干杯,
Alex


I'm relatively new to Git, but I want to give it a try (vs SVN and Bazaar).

Can anyone recommend me a workflow for a situation similar to the following:

  • 1 SVN repo, with several projects
  • 1 working copy "src"

The ideea is that in "src" I need to checkout project A or sometimes project B. Both projects have several branches.

For now, I have made 2 git clones of the SVN repo, one for each project. (I would have preferred --bare repos, but it does not work with git svn clone)

Then, I made a git repo in "src", and git remote add projA ..a_repo_git, "git remote add projB ..b_repo_git".

Now, I can see both of them from "src" using "git remote", and I can see their branches with "git remote show projA"

And now the trouble..

  • How can I get in "src" any of the branches in projA/projB ?
  • How can I modify them, and then be able to push them back (first to the git_repos, or directly to the SVN repo)?
  • Is this "workflow" ok, or do you have a better idea?

I did try in src: git checkout --track -b work_branch projA branch_in_A and after some fiddleing with "fetch" I managed to get the things. But then, I had problems pushing it back to the a_repo_git, and then to SVN. It was mostly trial and error.

I have to admit, I still have problems with remote branches! (and I get lost when I have to use "origin local_branch:origin_branch" or "origin origin_branch:local_branch", or "origin origin_branch" or "origin/origin_branch"! Back to the Git manual for some more reading.)

解决方案

I haven't updated the question, because in the last several days I was able to work really nice and easy with the help of my new repo :)

Here is what I did in the end:

Init two SVN repos in the same directory. (I can't rember at this time, but it may be possible that a "git init" was done in the same dir, before:

mkdir src && cd src
(not sure about this: git init)
git svn init --stdlayout --prefix=projA/ -RprojA file:///path/to/svn/repo/A
git svn init --stdlayout --prefix=projB/ -RprojB file:///path/to/svn/repo/B

The "--stdlayout" means that the SVN repos are in the standard format, with trunk, branches and tags on the same level.

The "--prefix" is used for the branches name. When we do "git branch -a", all SVN branches from project A have the prefix "projA" (ex: projA/branch_name_of_A). The same thing is for B.

The -R option sets the name of the SVN repo, inside of the git repo (it's the name we use with git when refering to the SVN repository/project)

The file:///path is the path to the SVN repo, and to the project inside the repo, in this case. I use "file://" because I used a flat-file repo, with no server. I am sure it work ok with http:// too, for a SVN server.

After this step, out of curiosity I had a look at the file src/.git/config. The two commands above created several "svn-remote" sections, one for each project (the -R option), and a generic one called "svn". I've modified the entries, so there will be only references to the projects. Each reference had entries for the repo path (fetch) and for tags/branches/trunk. If you look at the file, you'll understand what needs to be changed.

After this, I've fetched the contents of each project, using

git svn fetch projA #the contents of project A repo are downloaded
git svn fetch projB #the contents of project B repo are downloaded

Now, runnig "git branch -a" displayed all branches from the two repos, and the master branch (local). "git branch -r" did not displayed any branches; probably because they are "svn-remote" and not "remote"

The current "master" branch was pointing to the trunk of the second project. I've decided to get rid of it, since it would cause problems when switching from a project to the other.

I've created two new branches to point to the trunks of each project, then removed the "master" branch:

git checkout -b master_project_A projA/trunk
git checkout -b master_project_B projB/trunk
git branch -D master

And now, for the "workflow"; to work on project A:

git checkout master_project_A #switch to project A
git svn rebase #check for any updates on SVN repo
git checkout -b work_on_A master_project_A #create a branch starting from the master of project A

work work work on work_on_A; commit, etc

git checkout master_project_A #go back to master of project A
git svn rebase #check again for any update on SVN repo
git checkout work_on_A #go back to the work branch
git rebase master_project_A #update branch with any changes from the master of project A
git checkout master_project_A #go back to the master of project A
git merge work_on_A #merge to the master of project A the changes from the work branch
git svn dcommit #commit changes to the SVN repo, in trunk, because master_project_A was pointing to its trunk

If I want to checkout an existing branch from the SVN, I can do it with:

git checkout -b work_on_branch projA/branch_name

work work work

git svn rebase #update any changes from projA/branch_name
git svn dcommit #commit updates back to the branch in the SVN repo

For project B I can do the exact same things. In the end, I can have the contents of project A or B in the same dir "src", and have access to both projects on the SVN repository from the same git repo! :D

I still haven't figure it out how to create a local branch then push it to the SVN repo - I was close, but it didn't work.

Also, it may be useful to know the command "reset" ("git reset --hard projPrefix/branch") but I broke a few things using it, so it may be better to leave this for some other time.

I hope this helps someone!

Cheers, Alex

这篇关于我如何使用两个SVN项目和相应的git-svn分支与一个工作目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆