Git提交生成号码 [英] Git Commit Generation Numbers
问题描述
什么是git commit世代数字(黑客新闻链接),它们的意义是什么?
- 此处解释
提交的生成是历史图中的高度,如
从最远的根开始。它被定义为:
- 如果提交没有父母,那么它的世代为0。 >否则,它的世代比其父辈的最大值多1。
- 在2005年创建Git时已经提到过一个旧主题: b
$ b Linus Torwald(昨天,7月14日):
好的,所以我看到关于代数的旧讨论已经重新出现。
我必须说,在六年的git使用中,我认为代数概念多年来出现过几次并不是巧合:我认为缺乏代数是我们唯一真正的设计错误。
[...]
它实际上早在2005年7月就已经出现了,所以让我们在提交中使用世代数这个事情真的很老。
- 关于快速知道是否的问题一个提交是另一个提交的始祖(不必走回DAG - 提交图):
我认为说这个问题基本上归结为一个git问题是完全合理的:可以提交X是提交Y的祖先(作为一种基本限制某些算法的方法,一路走下去)。我们已经使用了提交日期,实际上它确实工作得很好。但它总是一个破坏的启发式。
所以,我个人认为生成计数器是进行提交日期比较的一种方式。如果只是说如果没有世代号码,我们会使用日期戳记,并且知道它们可能不正确,那就太好了。
使用日期戳回退事件可能涉及我们已经做的所有启发式检查(即检查邮票看起来是否正常,而不是只相信一个人)。
黑客新闻线程提到:
$ b
世代数是树状态的结果,而时间戳是从进行提交的环境(并且可能是不正确的!)环境中派生出来的。
此时,每个提交都存储对父树的引用。
的情况下从最新的提交本地排序。当您对
通过解析该树并阅读整个历史记录,您可以获得提交层次结构。
因为你需要在许多情况下命令提交,所以读取整个历史记录的效率非常低,所以git使用以确定提交顺序。
如果给定机器上的系统时钟关闭,这当然会失败。
使用世代号码,您可以获得在不需要依赖时间戳或读取整个树> n
,任何后来包含它的提交都会生成> n
,所以为了说明提交之间的关系,你只需要看看返回为n
,您可以立即获得任何中间提交的顺序。
与易于记忆无关。这是关于让git更加高效和强大的功能。 b $ b / ul> - 关于快速知道是否的问题一个提交是另一个提交的始祖(不必走回DAG - 提交图):
- If the commit has no parents, then its generation is 0.
- Otherwise, its generation is 1 more than the maximum of its parents generations.
- an old topic already mentioned at the creation of Git in 2005:
- about the question of quickly knowing if a commit is an ancestor of another commit (without having to walk back the DAG -- the graph of commits --):
- not redundant:
生成数字与父代表的实际历史结构完全一样多余
Linus:
不正确。如果您在该语句中添加...如果您解析整个历史记录,那只有这样。
我们从来没有分析整个历史,因为它太贵了,规模即可。所以现在我们依靠提交日期和一些黑客。
所以不,代数并不是多余的。它们是根本性的。这就是为什么六年前我们讨论过这个问题。
到哪里缓存这些信息(或者是否应该缓存),但从用户的角度来看,它仍然是关于一些容易记忆的信息(这不是承诺编号的目标):
所以它几乎,但不完全像其他人一直有的修订号?
是 - 差不多,但不完全。
如果你和我每个都创建了一个分支, $ c>#123 ,然后,据我了解,我的分支中的后续提交将是#124
,#125
等等,你的分支中的提交也是#124
,#125
对比这个
- 用CVS,在那里我会有1.124.1.1
,1.124.1.2
等等,你可以用1.124.2.1
,1.124.2.2
或
- 带Subversion,我可能会得到125
,128
和129
,而服务器提交了#124
,127
和130
以及其他人项目的不同部分得到了#126
。
只要开发线性地进行,在一个分支上,那么是的,这是关于将版本号保存在集中式RCS中的 - 一旦开始分支和合并,尽管它完全代表了一个不同的概念。
对于单个存储库,它与svn revnos有非常类似的解释。
您可以在特定存储库中提到分支的修订版#125。这通常正是你所需要的有关开发的人与人之间的沟通。
你能看看这个bug是不是处于不稳定状态? 我已经完成了所有变更,直到r245 prod
我猜如果中央服务器中的r245 prod是我本地回购的prodr100,因为我避难所克隆了完整的历史?
What are git commit generation numbers (hacker news link) and what are their significance?
解决方案Just to add to siri's answer, "Commit Generation Numbers" are:
A commit's generation is its height in the history graph, as measured from the farthest root. It is defined as:
Linus Torwald (yester, July 14th):
Ok, so I see that the old discussion about generation numbers has resurfaced.
And I have to say, with six years of git use, I think it's not a coincidence that the notion of generation numbers has come up several times over the years: I think the lack of them is literally the only real design mistake we have.
[...]
It actually came up as early as July 2005, so the "let's use generation numbers in commits" thing is really old.I think it's entirely reasonable to say that the issue basically boils down to one git question: "can commit X be an ancestor of commit Y" (as a way to basically limit certain algorithms from having to walk all the way down). We've used commit dates for it, and realistically it really has worked very well. But it was always a broken heuristic.
So yes, I personally see generation counters as a way to do the commit date comparisons right. And it would be perfectly fine to just say "if there are no generation numbers, we'll use the datestamps instead, and know that they could be incorrect".
That "use the datestamps" fallback thing may well involve all the heuristics we already do (ie check for the stamps looking sane, and not trusting just one individual one).
As the Hacker news thread mentions:
Generation numbers are a result of the state of the tree, while timestamps are derived from the ambient (and potentially incorrect!) environment from which the commit was made.
At the moment, each commit stores a reference to the parent tree.
By parsing that tree and reading the entire history you can obtain a hierarchy of commits.
Because you need to order commits in many situations, reading the entire history is extremely inefficient, so git uses timestamps to determine the ordering of commits.
This of course fails if the system clock on a given machine is off.
With a generation number, you can get an ordering locally from the latest commits, without having to rely on timestamps or read the entire tree.When you have a commit with generation
n
, any later commits that include it wound have generation>n
, so to tell the relation between commits, you only need look as far back asn
, and you can immediately get the order of any intermediate commits.
It has nothing to do with "easy to remember". It's about making git more efficient and robustGeneration numbers are completely redundant with the actual structure of history represented by the parent pointers.
Linus:
Not true. That's only true if you add "... if you parse the whole history" to that statement.
And we've never parsed the whole history, because it's just too expensive and doesn't scale. So right now we depend on commit dates with a few hacks.
So no, generation numbers are not at all redundant. They are fundamental. It's why we had this discussion six years ago.
There is still a debate as to where to cache that information (or if it should be cached), but for the user point of view, it still is about some "easy to remember" information (which isn't the goal of commit generation number):
So it's almost, but not quite, like the revision numbers everyone else has always had?
Yes -- almost, but not quite.
If you and I each create a branch off of a commit with gen#123
, then, as I understand it, the subsequent commits in my branch would be#124
,#125
, etc., and your commits in your branch would also be#124
,#125
, etc.Contrast this: - with CVS, where I would have
1.124.1.1
,1.124.1.2
, etc., and you would have1.124.2.1
,1.124.2.2
, or - with Subversion, where I might get revisions125
,128
, and129
, while the server gave your commits#124
,127
and130
, and someone else, on a totally different part of the project got#126
.As long as development proceeds linearly, on a single branch, then yeah, it's about the save as revision numbers in a centralized RCS -- once you start branching and merging, though, it represents a different concept entirely.
For a single repository, it does have a very similar interpretation to, say, svn revnos.
You can speak of "revision #125 of a branch" in a specific repository. Which is generally exactly what you need for human-to-human communication about development.
"Can you see if that bug is in r125 of unstable?" "I've got all changes up to r245 of prod"
I guess the confusing aspect would be if "r245 of prod" in the central server was "r100 of prod" in my local repo because I haven't cloned the full history?这篇关于Git提交生成号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- 如果提交没有父母,那么它的世代为0。 >否则,它的世代比其父辈的最大值多1。