一个 git repo 中的多个项目?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7033601/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:48:58  来源:igfitidea点击:

Multiple projects in one git repo?

gitsvn

提问by Michal M

I'm an SVN user at the moment and looking at moving my projects to git.

我目前是 SVN 用户,正在考虑将我的项目转移到 git。

I use one SVN repository to hold all the projects I create. My structure is something like this:

我使用一个 SVN 存储库来保存我创建的所有项目。我的结构是这样的:

/
    /group1
        /subgroup1
            /project1
                /branches
                    ...
                /tags
                    ...
                /trunk
                    ...
            /project2
                ...
        /subgroup2
            /project3
                ...
            /project4
                ...
    /group2
        /subgroup3
            ...
        /subgroup4
            ...
    /lib
        /lib1
        /lib2
        /lib3

As you can see I keep my projects in groups and /libcontains libraries shared between projects.

如您所见,我将我的项目分组并/lib包含在项目之间共享的库。

I chose this sort structure because:

我选择这种排序结构是因为:

  1. Similar repo structure was used in the company where I learned to use SVN.
  2. Allows me to have an svnserverunning as a service/daemon on my machine with all projects hosted on it (I don't like filepath approach).
  1. 在我学习使用 SVN 的公司中使用了类似的 repo 结构。
  2. 允许我svnserve在我的机器上将所有项目作为服务/守护程序运行(我不喜欢文件路径方法)。

Now... to the point. I was wondering:

现在……进入正题。我想知道:

How this sort of workflow would work if I were to move to git?

如果我要转移到 git,这种工作流程将如何工作?

Specifically:

具体来说:

  1. Would it be simple to migrate the repo tree to git?
  2. Assuming each project requires separate repo*, how would I be able to serve them all (ideally grouped in similar fashion) via svnservegit equivalent.
  1. 将 repo 树迁移到 git 会简单吗?
  2. 假设每个项目都需要单独的 repo*,我将如何通过svnservegit 等效项为所有项目提供服务(最好以类似的方式分组)。

*) I read about git and I understand that is the case, but I wanted to double check with experienced people.

*) 我读过关于 git 的文章,我知道情况确实如此,但我想与有经验的人仔细核对一下。

回答by manojlds

In Git, it is better to have each project in its own repo, and the libraries in another repo if needed and used as submodules ( equivalent of svn externals) in each project.

在 Git 中,最好将每个项目都放在自己的存储库中,如果需要,将库放在另一个存储库中,并在每个项目中用作子模块(相当于 svn externals)。

This is because in Git, a repo is a much more lightweight concept than SVN and also, more importantly, there is no ability to clone individual folders ( not to be confused with sparse checkout) within a repo separately like you are able to checkout and work on individual folders in SVN. So if you had all projects in a single repo, you will have to clone them all.

这是因为在 Git 中,repo 是一个比 SVN 轻得多的概念,而且,更重要的是,没有能力在一个 repo 中单独克隆单个文件夹(不要与稀疏检出混淆),就像您能够检出和在 SVN 中处理单个文件夹。因此,如果您在一个存储库中拥有所有项目,则必须将它们全部克隆。

Serving Git repos, using smart-http, git daemon and ssh is pretty straightforward. There is also Gitolitefor managing multiple repos ( including authorization and authentication). Read the linked chapter on ProGit on serving Git repos- http://progit.org/book/ch4-2.html

使用 smart-http、git daemon 和 ssh 为 Git 存储库提供服务非常简单。还有用于管理多个存储库(包括授权和身份验证)的Gitolite。阅读有关提供 Git 存储库的 ProGit 链接章节 - http://progit.org/book/ch4-2.html

Coming to your grouping, you can put the repos in folders as per your grouping structure, and serve using, say smart http method, whereby the repo urls will look like the urls that you would have used with SVN, will all projects seeming to be under the grouping etc.

进入您的分组,您可以根据您的分组结构将 repos 放在文件夹中,并使用智能 http 方法提供服务,其中 repo url 看起来像您在 SVN 中使用的 url,所有项目似乎都是在分组等下

回答by CodingWithSpike

In addition to the other answers, you can also use GitSlaveto link multiple git repos together.

除了其他答案之外,您还可以使用GitSlave将多个 git repos 链接在一起。

回答by svick

You couldhave all the projects in one repository, but it's really bad idea, because you always have to work with the whole repo.

可以将所有项目都放在一个存储库中,但这确实是个坏主意,因为您始终必须使用整个存储库。

To run a git server, if you need just one user (you), a server with installed git and ssh access is enough. See for example this article.

要运行 git 服务器,如果您只需要一个用户(您),安装了 git 和 ssh 访问权限的服务器就足够了。例如,参见这篇文章