简体   繁体   English

在git中,commit(s)和revision(s)之间有什么区别

[英]In git, what is the difference between a commit(s) and a revision(s)

There are a number of git commands, such as git clone --depth 10 <repo> , that require the number of revisions [ git help revisions ] to be given. 有许多git命令,例如git clone --depth 10 <repo> ,它们需要给出修订数[ git help revisions ]。

What is the distinction between a commit and a revision (in git, rather than say svn )? 提交和修订之间有什么区别(在git中, 而不是说svn )?

Or does it only show up in the plural when trying to count revisions/commits, eg that revisons must be counted by walking the DAG (directed acyclic graph) of commits and their parents, or some other careful distinction? 或者在尝试计算修订/提交时它是否只显示复数形式,例如,必须通过走向提交及其父母的DAG(有向无环图)或其他一些仔细区分来计算修订?

See " SPECIFYING REVISIONS " of git rev-parse : 请参阅git rev-parse的指定修订 ”:

A revision parameter <rev> typically, but not necessarily, names a commit object. 修订参数<rev>通常(但不一定)命名提交对象。
It uses what is called an extended SHA1 syntax, [and includes] various ways to spell object names. 它使用所谓的扩展SHA1语法,[并包括]各种方法来拼写对象名称。

So "revision" refers to the id you can use as a parameter to reference an object in git (usually a commit). 所以“修订版”是指你可以用作参数来引用 git中的对象(通常是提交)。

HEAD@{5 minutes ago} is a revision which reference the commit present 5 minutes ago. HEAD@{5 minutes ago}是一个修订版,引用了5分钟前提交的提交。

gitrevision mentions: gitrevision提到:

[...] some Git commands (such as git show ) also take revision parameters which denote other objects than commits , eg blobs ("files") or trees ("directories of files"). [...]某些Git命令(例如git show )也会使用修订参数来表示除提交之外的其他对象 ,例如blob (“文件”)或 (“文件目录”)。

For instance, the following rev parameter doesn't reference a commit: 例如,以下rev参数不引用提交:

<rev>:<path>, e.g. HEAD:README, :README, master:./README

A suffix : followed by a path names the blob or tree at the given path in the tree-ish object named by the part before the colon. 后缀:后跟路径命名由冒号前部分命名的树形对象中给定路径上的blob或树。


A "commit" in Git generally designates a "commit object " (as described in git commit-tree for instance): Git中的“提交”通常指定一个“提交对象 ”(例如,如git commit-tree中所述):

A commit encapsulates: 提交封装:

  • all parent object ids 所有父对象id
  • author name, email and date 作者姓名,电子邮件和日期
  • committer name and email and the commit time. 提交者姓名和电子邮件以及提交时间。

So: 所以:

  • a commit designates one of the git objects (others are blobs, tree, tags, notes), 一个提交指定一个 git对象(其他是blob,树,标签,注释),
  • a revision is a way to reference a git object. 修订是一种引用git对象的方法。

In your case ( git clone ) --depth <n> does: 在你的情况下( git clone )-- --depth <n>

Create a shallow clone with a history truncated to the specified number of revisions . 创建一个浅层克隆,其历史记录被截断为指定的修订数

It is for all the commits accessible at that depth, up to n revisions per path in the DAG. 它适用于在该深度可访问的所有提交,在DAG中每个路径最多n修订。
Since the result can be more than n commits, the term revision is more adapted here in order to emphasize you don't want just n commits, but any commits referenced by a max of n revisions accessible. 由于结果可能超过n提交,因此术语修订版更适用于此处,以强调您不仅仅需要n提交,而是可以访问最多n修订引用的任何提交。

However, in this context, revisions clearly reference only commits (as illustrated below) reachable (as you mentioned in " Is git clone --depth 1 (shallow clone) more useful than it makes out? "). 但是,在这种情况下,修订清楚地引用了只有提交(如下图所示)可达(如你在“ git clone --depth 1 (浅克隆)中提到的更有用吗? ”)。

The question is "reachable from what"? 问题是“可以从什么地方到达”?

You referenced this thread which included: 你引用了这个帖子 ,其中包括:

IIRC, --depth=<n> is not "deepen by <n> ", but " make sure I have at least <n> from the updated tip(s) ". IIRC, - --depth=<n>不是“加深<n> ”,而是“ 确保我从更新的提示中至少<n> ”。
The shallow-clone hack gives you quite useless (even though it may be internally consistent) semantics if you shallow-cloned way in the past and fetched with --depth after the other side added many more commits than <n> , as you cannot guess what the right value of <n> should be without actually fetching without --depth . 如果你在过去使用浅层克隆方式并且在另一方添加了比<n>更多的提交之后使用--depth获取浅层克隆hack,那么你很无用(即使它可能是内部一致的)语义,因为你不能如果没有--depth猜测<n>的正确值应该是没有实际获取的。

Interesting. 有趣。 I hadn't come across this distinction before but from skimming the documentation and my own experience, a commit in git is an object that points to a specific point in time in the history of the project (along with information on how it reached there). 我之前没有遇到过这种区别,但是从浏览文档和我自己的经验来看,git中的提交是指向项目历史中特定时间点的对象(以及它如何到达那里的信息) 。 A revision is superset of this that talks about different ways to reference a commit or a range of commits. 修订版是这个的超集,它讨论了引用提交或提交范围的不同方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM