如何在Git中管理项目的多个版本 [英] How to manage multiple versions of a project in Git

查看:892
本文介绍了如何在Git中管理项目的多个版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 git 进行版本控制的项目。很快,我将发布一个优质的托管版本的项目,但是专用于高级托管版本(性能等)的代码将会有所更改,这些代码不应该存在于开源版本中。 p>

我想避免拥有两个独立的目录/项目,因为如果我修复了开源版本中的错误,那么该错误最有可能出现在高级托管版本中。我不想在两个地方进行更改。



管理这个的最佳方法是什么?只需在 git 中分支将无法正常工作,因为某些文件需要2个版本:开源版本和高级版本。



感谢您的帮助。

解决方案

然而,分支应该可以工作,并且可以让您维护两个单独的版本。



如果您有一个适用于高级版本的错误,请将其修改为 master ,并且将它合并到溢价分支上。

Git将只合并你在 master 溢价,也就是您的错误修复。

另一种发布修补程序的方式都在 master premium 应该从共同祖先开始:请参阅 Git将修补程序合并到多个分支






2015年更新:git 2.5(2015年7月) c $ c> git-new-workdir 由新公司提供mmand git worktree add< ;路径> [< branch>]



更多信息,请参阅 使用Git的多个工作目录?




原始答案2012:



我 - 和提及评论命令 git-new-workdir

参见:




对此的一个解决方案是简单地为您的存储库创建另一个本地克隆。 Git会在本地克隆时自动使用硬链接,因此克隆速度非常快。

但是有一个问题:您现在有另一个需要保持更新的单独存储库。



这是 git-new-workdir 进来的地方。

不是做一个完整的克隆它只需为您设置一个新的工作目录(带有自己的索引)。

实际的存储库本身在原始工作目录和新工作目录之间共享。这意味着:


  • 如果您更新了一个存储库,那么新提交在所有其他工作目录中也立即可见。

  • 在您的一个工作目录中创建一个新的提交或分支,它们可以立即在所有工作目录中使用。



注意:即使提交自动出现,如果您有相同的分支签出,Git将不会更新工作副本。你必须自己做。



I have a project that is open sourced using git for revision control. Soon, I am going to release a premium hosted version of the project as well, but there will be changes made to the code specifically for the premium hosted version (performance, etc), that should not exist in the open source version.

I want to avoid having two separate directories/projects, because if I fix a bug in the open source version, that bug is most likely in the premium hosted version as well. I don't want to make changes in two places.

What is the best way to manage this? Simply branching in git won't work right, because some files need to have 2 versions: an open source version and a premium hosted version.

Thanks for the help.

解决方案

And yet, branching should work, and will allow you to maintain two separate versions.

If you have a bug which applies to the premium version, fix it on master, and merge it on premium branch.
Git will only merge what has changed since you branched between master and premium, ie your bug fix.
On another way to publish an hotfix both in master and premium would be to do it from the common ancestor: see "Git merging hotfix to multiple branches".


Update 2015: git 2.5 (July 2015) has replaced git-new-workdir presented below by the new command git worktree add <path> [<branch>].

For more, see "Multiple working directories with Git?".


Original answer 2012:

me-and mentions in the comments the command git-new-workdir.
See:

One solution to this is to simply create another local clone of your repository. Git automatically uses hard links when you clone locally, so cloning is very fast.
But there is one problem with this: You now have another, separate repository you need to keep up to date.

This is where git-new-workdir comes in.
Instead of doing a full-blown clone of your repository, it simply sets up a new working directory (with its own index) for you.
The actual repository itself is shared between the original and the new working directory. This means:

  • If you update one repository, the new commits are instantly visible in all other working directories as well.
  • Create a new commit or branch in one of your working directories, they’re instantly available in all working directories.

Note: Even though the commits are automatically there, Git won’t update the working copy if you’ve got the same branch checked out. You’ll have to do that for yourself.

这篇关于如何在Git中管理项目的多个版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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