为什么Git不将分支名称存储为提交的一部分? [英] Why does Git not store the branch name as part of the commit?

查看:123
本文介绍了为什么Git不将分支名称存储为提交的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

:请注意:我不想重启Mercurial或Git,我只是有一个技术问题,作为Mercurial用户,我不明白。我也不确定SO是否是提出这样一个问题的正确位置,但是与编程有关。

关于两个版本控制系统Git和Mercurial从用户的角度出发如何相互区别的讨论(例如 Mercurial和Git之间有什么区别? http://felipec.wordpress.com/2011/01/16/mercurial-vs-git-its-all-in-the-branches/ a>),主要区别在于处理分支。我已经阅读了许多这些讨论,但我一直在问自己这个问题:

为什么Git不将分支名称存储为提交的一部分?



我真的没有看到不这样做的好理由;这意味着数据不能简单地消失,因为没有任何引用(标签,分支,或其他)指向它。



我看到将提交中的分支存储为Mercurial的一大优点,因为这会使数据更加难以丢失。



Git支持Git分支模型的主要观点是,您可以简单地删除分支,但并不妨碍Git将分支的名称作为每次提交的一部分进行存储:如果分支的提交是删除,那么对该分支的引用也是如此。它也不会干扰廉价分支的说法:分支机构管理起来不会更昂贵。我认为不需要额外的存储空间:每次提交只需要几个字节。

其中一个关于Git和Mercurial分支的权威来源是SO问题:


在Git参考(分支机构,远程跟踪分支和标签)位于提交的DAG之外。


(允许管理分支机构的不同名称空间,本地和远程分支机构)

你有一个与Mercurial类似的书签分支(可以推/拉)的概念。

请注意,在Git中,数据不会消失,因为没有参考:您仍然有 reflog 来检索那些未引用的提交。


为什么Git没有将分支名称作为提交的一部分存储?

我没有看到不这样做的好理由


这个想法是从为什么 m ,即从更改的上下文(分支的名称)中分离 )。
因为您可以 fast-forward merge 分支,从一个分支提交可以在任何时间的一部分。



这就是为什么 JakubNarębski质疑Mercurialnam的设计(分支名称嵌入到变更集元数据中),尤其是使用全局名称空间,并非非常适合分布式版本控制系统。



您创建了一个分支来隔离开发工作(请参阅什么时候应该分支?),但是对于DVCS,开发工作(提交集合)应该在任何分支名称下发布。一旦发布到其他Git仓库,您定义的本地上下文(分支名称)可能无效。


Please note: I'm not trying to restart the argument whether Mercurial or Git is better, I just have a technical question that I, as a Mercurial user, don't understand. I'm also not sure whether SO is the right place to ask such a question, but it is programming related.

There have been many discussions about how the two version control systems Git and Mercurial differ from each other from a user's point of view (e.g. What is the Difference Between Mercurial and Git? and http://felipec.wordpress.com/2011/01/16/mercurial-vs-git-its-all-in-the-branches/ ), and the major difference is the handling of branches. I have read through many of these discussions, but I keep asking myself this question:

Why does Git not store the branch name as part of the commit?

I don't really see a good reason for not doing that; it means that data can't just simply vanish because there is no reference (tag, branch, whatever) poiting to it.

I see storing the branch in the commit as a big plus for Mercurial, because that makes it more difficult to lose data.

The main point of the Git crowd in favor of Git's branching model, that you can simply delete branches, does not prevent Git from storing the name of the branch as part of each commit: If the commits of a branch are deleted, so are the references to that branch. It will also not interfere with the "cheap branching" argument: branches will not be more expensive to manage. And I don't think that the additional storage needed should be of concern: it's just a couple of bytes per commit.

解决方案

One of the definitive source about branches for Git and Mercurial is the SO question:

"Git and Mercurial - Compare and Contrast"

In Git references (branches, remote-tracking branches and tags) reside outside DAG of commits.

(That allows to manage different namespaces regarding branches, for local and remote branches)

You have a similar notion with Mercurial with bookmark branches (which can be pushed/pulled).

Note that in Git, the data won't "vanish" because there is no reference: you still have the reflog to retrieve those unreferenced commits.

Why does Git not store the branch name as part of the commit?
I don't really see a good reason for not doing that

The idea is to separate what has changed (the commits) from whym ie from the context of the change (the name of the branch).
Since you can fast-forward merge a branch, commits from one branch can be part of another at any time.

That is why Jakub Narębski questioned the design of Mercurial "named branches" (with branch names embedded in changeset metadata), especially with a global namespace, not very suited for a distributed version control system.

You create a branch to isolate a development effort (see "When should you branch?"), but with a DVCS, that development effort (the set of commits) should be published under any branch name. What local context (branch name) you have defined might not be valid once published to another Git repo.

这篇关于为什么Git不将分支名称存储为提交的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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