什么是 git“快照”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4964099/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 10:04:42  来源:igfitidea点击:

What is a git "Snapshot"?

git

提问by jens

The official Git docsays:

官方 Git 文档说:

$ git diff test

This will show you what is different between your current working directory and the snapshot on the 'test' branch

$ git diff test

这将向您显示当前工作目录与“test”分支上的快照之间的不同之处

As a newbie this is very confusing. I've never heard of the term snapshot. Do they mean the "HEAD" of the "test" branch?

作为一个新手,这很令人困惑。我从来没有听说过快照这个词。他们是指“test”分支的“HEAD”吗?

采纳答案by Femaref

A snapshot is the state of something (e.g. a folder) at a specific point in time. In this case, snapshot means the current content of the test branch, this doesn't have to be the head revision.

快照是某物(例如文件夹)在特定时间点的状态。在这种情况下,快照意味着测试分支的当前内容,这不一定是头部修订。

回答by philippe

The term snapshot is used in the git reference site as well

术语快照也用于 git 参考站点

It is the replacement term for "Revision". In other version control systems, changes to individual files are tracked and refered to as revisions, but with git you are tracking the entire workspace, so they use the term snapshot to denote the difference.

它是“修订”的替代术语。在其他版本控制系统中,对单个文件的更改会被跟踪并称为修订,但使用 git 您正在跟踪整个工作区,因此它们使用术语快照来表示差异。

From http://gitref.org/index.html

来自http://gitref.org/index.html

Instead of writing a tool that versions each file individually, like Subversion, we would probably write one that makes it easier to store snapshots of our project without having to copy the whole directory each time.

This is essentially what Git is. You tell Git you want to save a snapshot of your project with the git commit command and it basically records a manifest of what all of the files in your project look like at that point. Then most of the commands work with those manifests to see how they differ or pull content out of them, etc.

If you think about Git as a tool for storing and comparing and merging snapshots of your project, it may be easier to understand what is going on and how to do things properly.

我们可能会编写一个工具,而不是像 Subversion 那样编写一个单独版本每个文件的工具,而是编写一个可以更轻松地存储项目快照的工具,而不必每次都复制整个目录。

这本质上就是 Git。你告诉 Git 你想用 git commit 命令保存项目的快照,它基本上记录了项目中所有文件在那时的样子的清单。然后,大多数命令与这些清单一起使用,以查看它们的不同之处或从中提取内容等。

如果您将 Git 视为用于存储、比较和合并项目快照的工具,则可能更容易理解正在发生的事情以及如何正确地做事。

回答by anKotliner

In order to explain the term-snapshot clear. Please allow me to introduce the other two things

为了解释清楚术语-快照。请允许我介绍另外两件事

  1. git loose object format
  2. git Packfiles
  1. git松散对象格式
  2. git 包文件

Assume we have a file called "a.txt" which contents are ten 'a' letters under git control. After we commit this file, it will create three folders under .git/objects path and each folder has one file. Each file is S.N.A.P.S.H.O.T.

假设我们有一个名为“a.txt”的文件,它的内容是 git 控制下的十个“a”字母。我们提交这个文件后,它会在 .git/objects 路径下创建三个文件夹,每个文件夹都有一个文件。每个文件都是SNAPSHOT

a.txt file under git control which has been committedthree folders created by git after committed

git控制下已经提交的a.txt文件提交后git创建的三个文件夹

Each folder has one file

每个文件夹有一个文件

enter image description here

在此处输入图片说明

Nowwe edit the a.txt file to see what happens

现在我们编辑 a.txt 文件看看会发生什么

We changed the first letter 'a' to letter 'b'

我们将第一个字母“a”改为字母“b”

enter image description here-->> enter image description here

在此处输入图片说明-->> 在此处输入图片说明

Then committed!

然后答应了!

Git created other three new files under three new folders

Git 在三个新文件夹下创建了另外三个新文件

enter image description here

在此处输入图片说明

These three new files are S.N.A.P.S.H.O.Ts

这三个新文件是快照

enter image description here

在此处输入图片说明

Every time we do COMMIT git will save snapshotsto disk instead of the delta between the new version to old version of the same file. Even if we just changed one letter of one file, git will save whole file as a snapshot.

每次我们执行 COMMIT 时,git 都会将快照保存到磁盘,而不是同一文件的新版本到旧版本之间的增量。即使我们只是更改了一个文件的一个字母,git 也会将整个文件保存为快照

This also called the loose object format.

这也称为松散对象格式

In this case, git will coast more disk space than the other vcs (such as subversion).

在这种情况下,git 将比其他 vcs(例如 subversion)消耗更多的磁盘空间。

But the brilliant git will do another job (git gc) after this from time to time which created PACKFILESand remove the snapshot which contents are similar to shrink the size of itself.

但是在此之后,出色的 git 会不时执行另一项工作 (git gc),这会创建PACKFILES并删除内容类似的快照以缩小自身的大小。

The packfiles is under .git/objects/pack

包文件在 .git/objects/pack 下

You can see it after execute "git gc" command by yourself.

自己执行“git gc”命令后就可以看到了。

回答by xged

Snapshotis to a repository as screenshot is to a video.

快照对于存储库就像屏幕截图对于视频一样。

It's the content (files and folders) of a repository at some point in time, a state of a repository, if you will.

它是某个时间点存储库的内容(文件和文件夹),存储库的状态,如果您愿意的话。

That content is represented by git's Tree Objectand stored in the .gitfolder. When you commit, you store your repository's current working directoryas a new repository's snapshot. Your Git repository consists of series of snapshots, other VCS consists of series of diffs instead.

该内容由 git 的Tree 对象表示并存储在.git文件夹中。时commit,您将存储库的当前工作目录存储为新存储库的快照。您的 Git 存储库由一系列快照组成,而其他 VCS 则由一系列差异组成。

回答by Marcelo Cantos

Firstly, that's not the official git documentation. It's a community-authored book. While it is probably fairly authoritative, it isn't gospel.

首先,这不是官方的 git 文档。这是一本社区创作的书。虽然它可能相当权威,但它不是福音。

AFAIK, "snapshot" doesn't have any formal meaning in git. Certainly the git diff manpagedoesn't mention it. In the given context, it is probably an informal reference to how the "test" branch is being used in the examples within the book, i.e., as a snapshot of ongoing work, for testing purposes.

AFAIK,“快照”在 git 中没有任何正式含义。当然git diff 联机帮助页没有提到它。在给定的上下文中,它可能是对如何在本书中的示例中使用“测试”分支的非正式参考,即作为正在进行的工作的快照,用于测试目的。

回答by brent777

My understanding is that a snapshot in general is just the "entity" that git uses to store its data. As opposed to storing its data as a series of "deltas" / changesets like SVN does, for example, each commit that you do to git creates a "commit object" that references a snapshot of what the code looked like at that point in time.

我的理解是,快照通常只是 git 用来存储其数据的“实体”。例如,与像 SVN 那样将其数据存储为一系列“增量”/变更集相反,例如,您对 git 所做的每次提交都会创建一个“提交对象”,该对象引用该时间点代码外观的快照.

So as @Femaref says, it is the state of the code at a specific time and does not necessarily mean it is the head of the test branch but could be in the example you saw.

所以正如@Femaref 所说,它是特定时间的代码状态,并不一定意味着它是测试分支的头部,但可能在您看到的示例中。

回答by G_V

Based on the other definitions posted:

基于发布的其他定义:

A snapshot is a representation of the current stateof your tracked files in the form of a manifest, which can be compared with other manifests to see where the differences are.

快照是以清单的形式表示您的跟踪文件的当前状态,可以将其与其他清单进行比较以查看差异所在。

Git only tracks the differences between manifests from the first moment it was tracked. If a file has not been changed since the very first snapshot, all subsequent snapshots will refer to the very first snapshot. If the file has been changed, all subsequent snapshots will refer to the snapshot that has the most recent changes. What git stores is effectively a chained history of snapshots from the last to the very first. A branch is basically a split in the timeline, allowing for an alternate historical chain of snapshots from a specific snapshot on the main chain.

Git 仅从第一次跟踪清单开始就跟踪清单之间的差异。如果文件自第一个快照以来没有更改,则所有后续快照都将引用第一个快照。如果文件已更改,则所有后续快照都将引用具有最新更改的快照。git 存储的实际上是从最后到第一个快照的链式历史记录。分支基本上是时间线中的一个分割点,允许从主链上的特定快照创建一个备用的历史快照链。

Branches are usually intended for features and such that may at some point be merged into the main branch. If there's no intention merge, but rather a divergence from the original project in the form of a new and entirely separate copy of the project with its own history, it's often called a hard fork, referring to "a fork in the road".

分支通常用于功能,并且可能在某些时候合并到主分支中。如果没有意图合并,而是以具有自己历史的项目的新的且完全独立的副本的形式与原始项目发生分歧,则通常称为硬分叉,指的是“道路上的分叉”。

回答by Ltf4an

Following are some of the contexts in which the term snapshotis used:

以下是使用术语快照的一些上下文:

  1. A new commit is created by taking a snapshot of the Index.
  2. A commit is a snapshot of the repo at a given time.
  1. 通过拍摄索引的快照来创建新的提交。
  2. 提交是给定时间的回购快照。