存储库中的分支是什么?

发布于 2024-09-03 08:20:59 字数 515 浏览 2 评论 0原文

根据我对 Subversion 的理解,如果您有一个包含多个项目的存储库,那么您可以在该存储库中分支各个项目(请参阅 SVN 红皮书 - 使用分支

但是,我不太明白的是,当您在分布式系统之一(Git、Hg、Bazaar - I)中创建分支时会发生什么认为哪一个并不重要)。您可以仅对存储库的子目录进行分支,还是在创建分支时对整个存储库进行分支?

这个问题是我在超级用户上发布的一个更大问题的一部分(版本控制的选择和设置),并且是在我试图弄清楚如何最好地控制独立项目的大型层次结构布局时出现的。

对于分布式系统来说,我想做的最好是通过某种子项目机制来处理——但这也是我不清楚的,尽管我听说过关于 git 的术语。

From what I understand of subversion if you have a repo that contains multiple projects, then you can branch individual projects within that repo (see SVN Red book - Using Branches)

However what I don't quite follow is what happens when you create a branch in one of the distributed systems (Git, Hg, Bazaar - I don't think it matters which one). Can you branch just a sub-directory of the repo, or when you create the branch are you branching the entire repo?

This question is part of a larger one that I posted on superuser (choice and setup of version control) and has come about as I am trying to figure out how to best version control a large hierarchal layout of independent projects.

It may be that for distributed systems that what I would like to do is best handled by a sub-project mechanism of some sort - but again that is something I am not clear on although I have heard the term mentioned in regards to git.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

野稚 2024-09-10 08:20:59

使用 bazaar,如果您在共享存储库中创建两个分支,则它们拥有的任何共同历史记录都位于存储库中,而不是分支本身 - 分支仅引用它。这可以为具有不同功能的同一项目的许多分支的存储库节省磁盘空间,并加快新分支的创建速度(您不必复制包含分支历史记录的文件)。我已经有一段时间没有查看 hg 和 git 了,但我不相信它们有与此相同的功能。

Bazaar 没有子项目。分支是一个完整的、连续的单元。您不能对其部分进行分支。不过,我相信 git 和 hg 都有子分支。

With bazaar, if you create two branches in a shared repository, any common history they have lives within the repository and not the branch itself - the branch merely references it. This saves disk space for repositories that have many branches of the same projects for different features as well as speeds up the creation of new branches (you're not having to duplicate the files containing branch history). It's been a while since I looked at hg and git, but I do not believe they have a feature identical to this.

Bazaar does not have sub-projects. A branch is a whole, contiguous unit. You cannot branch portions of it. I believe git and hg both have sub-branches, though.

何以畏孤独 2024-09-10 08:20:59

Subversion 是集中式的,您可以根据需要在一个存储库中组织您的项目。
由于branchbes被模拟为SVN的目录,因此您最终会混合:

但带有 DVCS,每个存储库都是其自己的组件(或模块)。
也就是说,您不想将所有项目放在一个存储库中。
相反,您使用的是子模块(Git)或子存储库(Hg)

这样您就可以将分支作为纯粹的历史隔离:
当您进行分支时,all 存储库的历史记录会创建一个新分支,准备记录(引用)您将进行的任何新提交。
这不是“廉价复制品”,只是一个新的指针。
注意:Mercurial 有一个更复杂的分支模型,其中可能涉及克隆存储库以创建新分支,但分支背后的一般原则仍然存在。

Subversion being centralized, you can organize your projects within one repo as you want.
Since branchbes are emulated as directory with SVN, you end up mixing:

  • history isolation (which is the main purpose of a branch: you isolate the versions of a set of files from other versions from the same set of files)
  • "component" isolation (a component or module being a group of files each in their own directory)

But with a DVCS, each repository is its own component (or module).
I.e. you don't want to put all your projects within one repo.
Rather you are using submodules (Git) or subrepos (Hg).

That leaves you with the branch as a pure history isolation:
Whe you branch, the history of the all repo creates a new branch ready to record (reference) any new commit you will make.
The is no "cheap copy", just a new pointer made.
Note: Mercurial has a more complex branching model which can involve cloning a repo to create a new branch, but the general principle behind branching stands.

遗心遗梦遗幸福 2024-09-10 08:20:59

对于 git,分支只是指向分支顶端提交的指针。它本身不包含任何信息。因此,您的历史记录可能如下所示:

- o - o - o - o - o (branchA)
           \
            o - o (branchB)

每个 o 都有一个提交,它代表整个存储库在该点的状态。因此,这两个分支通常代表整个存储库的不同状态,尽管它们可能仅在一个子目录的内容上有所不同。不过,肯定不会有任何空间浪费;如果两次提交使用给定文件的相同版本,则它们在内部指向其内容的同一对象。

根据您实际想要执行的操作,您可能有兴趣使用 子模块 ,这本质上是一种将存储库放置在存储库中的机制,这样您就可以拥有一个包含子项目(嵌入式)存储库的元项目存储库。

With git, a branch is simply a pointer to the commit at the tip of the branch. It doesn't contain any information of its own. So, your history might look like this:

- o - o - o - o - o (branchA)
           \
            o - o (branchB)

Each o there is a commit, which represents the state of the entire repository at that point. The two branches thus in general represent different states of the entire repo, though it could be that they only differ in the contents of one subdirectory. There certainly won't be any wasted space, though; if two commits use the same version of a given file, they internally point to the same object for its contents.

Depending on what you're actually trying to do, you could be interested in using submodules, which are essentially a mechanism for placing repos inside of repos, so that you can have a meta-project repository which contains sub-project (embedded) repositories.

旧街凉风 2024-09-10 08:20:59

一般来说,分布式版本控制系统只支持您从整个现有分支中创建一个新分支,而不是(像 Subversion 那样)允许您复制正在处理的一小部分内容。 Git 至少(我认为其他一些)允许您引用子模块(它们本身就是 git 存储库)。

Git 确实允许您做几乎任何您想做的事情,即使它不是特别有用或明显(即使这些工具不会真正支持您这样做)。没有任何技术原因可以解释为什么 Git 存储库中的所有分支都需要有一个共同的父分支或者彼此之间有任何关系。也没有什么可以阻止您构建一个由其父提交的子树组成的提交,并且 Git 的更改跟踪和合并实际上可能会很好地应对这种情况。

Mercurial 至少在这方面与 Git 不同,因为 Mercurial 工作流程似乎是为尝试将单独的分支保留在单独的存储库中而量身定制的,而 git 工作流程则非常乐意在同一存储库中拥有多个分支。

In general, distributed version control systems will only support you to create a new branch out of the whole of an existing branch, rather than (as Subversion does) allowing you to make a copy of a small part of what you're working on. Git at least (and I think some of the others) allows you to reference sub-modules (which are git repositories in their own right).

Git does allow you to do pretty much anything you want, even if it's not particularly useful or obvious (and even if the tools won't really support you in doing it). There's no technical reason why all the branches in a Git repository need to have a common parent or have anything to do with each other at all. There's also nothing stopping you constructing a commit consisting of a sub-tree of its parent commit and Git's change tracking and merging will actually probably cope quite well in this case.

Mercurial at least differs from Git in this regard, as the Mercurial workflow seems tailored to trying to keep separate branches in separate repositories while the git workflow is quite happy with having many branches in the same repository.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文