Git如何解决合并问题? [英] How does Git solve the merging problem?

查看:114
本文介绍了Git如何解决合并问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SVN通过使分支真的很便宜而使分支变得更容易,但合并在SVN中仍然是一个真正的问题 - Git可以解决这个问题。

Git是否实现了这个目标,并且如何?



(免责声明:我所知道的Git基于Linus讲座 - 总git noob在这里)

Git不会阻止合并中的冲突,但即使它们不共享任何父代祖先,也可以协调历史记录。

(through /community.livejournal.com/evan_tech/255341.htmlrel =noreferrer>移植文件( .git / info / grafts ,它是一个列表,每行一个,其父母提交一个提交,你可以修改这个调和的目的。)

在那里非常强大。



但是为了真正了解如何合并已被认为通过,您可以通过turnin开始g给Linus自己,并意识到这个问题与算法无关:


Linus

em>:我个人,我想拥有非常重复和非巧妙的东西。我理解的东西告诉我它不能做到这一点。

坦率地说,合并单个文件历史而不用取得所有其他文件考虑到历史使我走了唉。



合并的重要部分不在于它如何处理冲突(需要由人类验证无论如何,如果他们都非常有趣),但它应该将历史融合在一起,以便为未来的合并打下坚实的基础。

换句话说,重要的部分是微不足道的部分:父母的命名,以及他们之间的关系。不是冲突。



看起来似乎有99%的供应链管理员似乎认为解决方案就是对内容合并更聪明。完全没有提到这一点。







所以Wincent Colaiuta补充道(重点是我的):


无需花哨的元数据,重新命名跟踪等等。

您需要的唯一一件事存储是每次更改前后的树状态。

什么文件被重命名?哪些被复制?哪些被删除?添加了哪些行?哪些被删除?哪些线路内部发生了变化?哪些文本块从一个文件复制到另一个文件?

您不应该关心这些问题中的任何一个,并且您当然不应该保留特殊的跟踪数据以帮助您回答它们:对树的所有更改(添加,删除,重命名,编辑等)都隐式编码在树的两种状态之间的增量中。您只需 track 内容

绝对的一切都可以(也应该)推断



Git打破了模式,因为它考虑内容而不是文件。 b $ b它不会跟踪重命名,它会跟踪内容。而且它在整个树层面都这样做。

这与大多数版本控制系统是完全不同的。

它并不试图存储每个文件的历史记录;它会将历史存储在树级别。

当您执行差异时,您将比较两棵树,而不是两个文件。

智能设计决定是Git如何合并。

合并算法很聪明,但他们不会太聪明。毫不含糊的决定是自动做出的,但是如果有人怀疑是由用户决定的话。

这是应该的。你不想让机器为你做出这些决定。你永远不会想要它。

这是Git合并方法的基本见解:当其他版本控制系统试图变得更加智能时,Git很乐意自我描述为愚蠢的内容管理器,并且它更好。



SVN made branching much easier by making branches really cheap, but merges remain a real problem in SVN - one that Git supposedly solves.

Does Git achieve this, and how?

(disclaimer: All I know about Git is based on the Linus lecture - total git noob here)

解决方案

Git will not prevent conflict in merges but can reconcile history even when they do not share any parent ancestor.
(through The grafts file (.git/info/grafts), which is a list, one per line, of a commit followed by its parents, that you can modify for that "reconciliation" purpose.)
So pretty powerful right there.

But to really have a glimpse on "how merges have been thought through", you can start by turning to Linus himself, and realize this issue is not so much about "algorithm":

Linus: Me personally, I want to have something that is very repeatable and non-clever. Something I understand or tells me that it can't do it.
And quite frankly, merging single-file history without taking all the other files' history into account makes me go "ugh".

The important part of a merge is not how it handles conflicts (which need to be verified by a human anyway if they are at all interesting), but that it should meld the history together right so that you have a new solid base for future merges.

In other words, the important part is the trivial part: the naming of the parents, and keeping track of their relationship. Not the clashes.

And it looks like 99% of SCM people seem to think that the solution to that is to be more clever about content merges. Which misses the point entirely.


So Wincent Colaiuta adds (emphasis mine):

There is no need for fancy metadata, rename tracking and so forth.
The only thing you need to store is the state of the tree before and after each change.

What files were renamed? Which ones were copied? Which ones were deleted? What lines were added? Which ones were removed? Which lines had changes made inside them? Which slabs of text were copied from one file to another?
You shouldn't have to care about any of these questions and you certainly shouldn't have to keep special tracking data in order to help you answer them: all the changes to the tree (additions, deletes, renames, edits etc) are implicitly encoded in the delta between the two states of the tree; you just track what is the content.

Absolutely everything can (and should) be inferred.

Git breaks the mould because it thinks about content, not files.
It doesn't track renames, it tracks content. And it does so at a whole-tree level.
This is a radical departure from most version control systems.
It doesn't bother trying to store per-file histories; it instead stores the history at the tree level.
When you perform a diff you are comparing two trees, not two files.

The other fundamentally smart design decision is how Git does merges.
The merging algorithms are smart but they don't try to be too smart. Unambiguous decisions are made automatically, but when there's doubt it's up to the user to decide.
This is the way it should be. You don't want a machine making those decisions for you. You never will want it.
That's the fundamental insight in the Git approach to merging: while every other version control system is trying to get smarter, Git is happily self-described as the "stupid content manager", and it's better for it.

这篇关于Git如何解决合并问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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