简体   繁体   English

用于Web开发的Git-SVN - 如何做到这一点?

[英]Git-SVN for Web development — how to do it?

we use SVN for our work. 我们使用SVN进行工作。 We are a small web design studio and we write in PHP developing some kind of "framework" in the mean time. 我们是一个小型网页设计工作室,我们用PHP编写同时开发某种“框架”。

Now we are thinking about a more powerful solution and we would like to try git-svn. 现在我们正在考虑一个更强大的解决方案,我们想尝试git-svn。 We use branches as different projects — one branch, one project. 我们使用分支作为不同的项目 - 一个分支,一个项目。 So I have in my computer exactly the same structure as in my wwwroot. 所以我的计算机中的结构与我的wwwroot结构完全相同。 One branch = one project = one virtualhost. 一个分支=一个项目=一个虚拟主机。

As I played with git-svn I don't know how to achieve this with it. 当我玩git-svn时,我不知道如何用它来实现这个目标。 I need the branches to be physically present in the filesystem because I have virtulhosts in Apache etc. 我需要将分支实际存在于文件系统中,因为我在Apache等中有virtulhosts。

Can you please give me some advice or point me to some tutorial how to do it? 你能给我一些建议或指点一些教程怎么做?

You're doing it wrong™. 你做错了。

Seriously, branches are meant for, well, branches. 说真的,分支是指分支。 You should use different repositories for different projects. 您应该为不同的项目使用不同的存储库。

If I'm getting this right, you have a single framework you're working on, and several projects based on that framework. 如果我做对了,你有一个你正在研究的框架,以及几个基于该框架的项目。 No matter what revision control system you use, that translates to one repository for the framework, and one repository for each project. 无论您使用何种版本控制系统,都会转换为框架的一个存储库,以及每个项目的一个存储库。

This is the reason git shows you only one branch at a time in your working copy. 这就是git在工作副本中一次只显示一个分支的原因。 You usually work on a single branch at a time. 您通常一次只在一个分支上工作。 You need one working copy per branch if you need to have working copies of all branches. 如果需要拥有所有分支的工作副本,则每个分支需要一个工作副本。

Time has shown us the best solution. 时间向我们展示了最佳解决方案。

We switched to git completely with a new major version of our framework. 我们完全使用我们框架的新主要版本切换到git。 So the projects based on an older version are still maintained through the SVN repository and the new development is running in git. 因此,基于旧版本的项目仍然通过SVN存储库进行维护,新开发在git中运行。

You can do similar thing with Git itself - see Git submodules . 你可以用Git本身做类似的事情 - 参见Git子模块

In this way you have a Git repo for whole "wwwroot" and submodules for each project. 通过这种方式,您可以为每个项目提供整个“wwwroot”和子模块的Git仓库。 If your working only on a few projects of all you can check them out/clone separately. 如果你只在几个项目中工作,你可以分别检查/克隆。

I have never found git-svn to be a good solution. 我从未发现git-svn是一个很好的解决方案。 I either use SVN or Git, not both. 我要么使用SVN,要么使用Git,而不是两者。

Having just switched from svn to Git myself, I'd agree with the two answers above. 刚刚从svn切换到Git,我同意上面的两个答案。

I'd also recommend against using git-svn (except perhaps to import your existing svn repositories into Git, as a once-off one-way event). 我还建议不要使用git-svn(除了可能将现有的svn存储库导入Git,作为一次性单向事件)。 And I'd also recommend using a separate Git repository for each project. 我还建议为每个项目使用单独的Git存储库。

With svn, some people like to use a single repository because it's easier to share code between projects, etc. With Git, you're better using a single additional repository for all your shared stuff; 使用svn,有些人喜欢使用单个存储库,因为它更容易在项目之间共享代码等。使用Git,您最好为所有共享资源使用单个额外的存储库; if something starts out in one project and you later want to share it, do a subtree merge (that's a specifically-documented Git term, by the way) into your shared repository. 如果某个项目中的某些事情开始并且您以后想要共享它,请将子树合并(顺便说一句,这是一个特别记录的Git术语)合并到您的共享存储库中。 Then you can pull the code back to your other projects. 然后,您可以将代码拉回到其他项目中。

As others have said, use separate repositories, not branches. 正如其他人所说,使用单独的存储库,而不是分支。

With SVN, you could just have.. 有了SVN,你可以......

http://svn/site_a/trunk/
http://svn/site_b/trunk/
etc

Then you can svn co http://svn/site_a/trunk/ each site separately 然后你可以单独svn co http://svn/site_a/trunk/每个站点

With git, you would just create multiple repositories: 使用git,您只需创建多个存储库:

mkdir site_a
cd site_a
git init
cd ../
mkdir site_b
cd site_b
git init

You could have a "master" repository with each site added as a sub-module, but this is not what git-submodule is intended for, and I found it more trouble than it's worth. 您可以拥有一个“主”存储库,每个站点都作为子模块添加,但这不是git-submodule的用途,我发现它比它的价值更麻烦。

It's not a very good idea to use git-svn for anything more than migrating an SVN repo to git, or working on a project you don't control. git-svn用于将SVN repo迁移到git,或者处理你无法控制的项目,这不是一个好主意。

If you want to use gits branching (and it's other benefits), why not switch entirely to git? 如果你想使用gits分支(以及它的其他好处),为什么不完全切换到git? You can set it up in a somewhat-SVN-like centralised-fashion, using something like gitosis 您可以使用类似gitosis的东西,以类似SVN的集中式方式进行设置

Basically, if you like git, switch to it (rather than using git-svn ). 基本上,如果你喜欢git,请切换到它(而不是使用git-svn )。 If you are looking at git just for the branching, do not - split your SVN repository into smaller projects ( site_a/trunk/ and so on) 如果你正在寻找git只是为了分支,不要 - 将你的SVN存储库拆分成更小的项目( site_a/trunk/等)

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

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