为什么在提交之前在存储库中出现斑点

为什么在提交之前在存储库中出现斑点

本文介绍了为什么在提交之前在存储库中出现斑点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我在Pro Git的3.1节中遇到了以下段落:

So I came across the following passage in section 3.1 of Pro Git:

让我们假设您有一个包含三个文件的目录,并将它们暂存并提交.暂存文件将为每个文件计算一个校验和(我们在入门中提到的SHA-1哈希),存储该版本的Git存储库中的文件(Git将它们称为blob),并将该校验和添加到暂存区中."

"Let’s assume that you have a directory containing three files, and you stage them all and commit. Staging the files computes a checksum for each one (the SHA-1 hash we mentioned in Getting Started), stores that version of the file in the Git repository (Git refers to them as blobs), and adds that checksum to the staging area"

我的问题是:为什么在提交这些文件之前git将文件的版本存储在Git存储库中"?

My question is this: Why does git "store a version of the file in the Git repository" prior to me committing those files?

推荐答案

有一个非常机械的答案(我看到的是注释中提到的siride ):Git的 index 的内部结构,即Git用于构建 next 提交的神秘对象,仅存储blob哈希ID .因此,为了在索引中有文件的副本(以便在下一次提交中使用),它必须作为blob对象在存储库中.

There's a very mechanical answer (which I see siride mentioned in a comment): the internal structure of Git's index, that mysterious object that Git uses to build up the next commit, stores only blob hash IDs. Therefore, in order to have a copy of the file in the index (so that it will be in the next commit), it must be in the repository as a blob object.

有一个性能答案:通过将哈希ID存储在索引中,Git可以非常快速地进行新的提交.

There's a performance answer: by storing hash IDs in the index, Git makes new commits very quickly.

有一个数据恢复的答案(有点弱):通过将blob预先存储在存储库中,如果您不小心对它做了一些坏的事情,可以通过git fsck --lost-found将它恢复一段时间. (这里的弱点是或包括,如果斑点与存储库中的现有斑点匹配,则不会出现在丢失的搜索中;并且您会丢失文件的 name ,这通常是对理解其内容很重要.)

There's a data-recovery answer (which is kind of weak): by storing the blob in the repository in advance, you can get it back for a while, via git fsck --lost-found, if you accidentally do something bad to it. (The weaknesses here are, or include, that if the blob matches an existing blob in the repository, it does not show up in the lost-found search; and you lose the file's name, which is often important to understanding its content.)

有一个设计美学的答案:也许Linus认为git add file较早地将文件复制到存储库中比在git commit以后进行复制更漂亮.

There's a design-aesthetic answer: perhaps Linus thought that git add file copying the file into the repository early was prettier than having git commit do it later.

您可以选择这些答案中的任何一个,也可以自己编写答案!

You can choose any of these answers, or make up your own!

这篇关于为什么在提交之前在存储库中出现斑点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 16:07