为什么 "git index" 有这么多名字?

Why does the "git index" have so many names?

在阅读如何使用 Git 时,我发现 git index 有很多不同的名称。

他们是:

为什么有这么多选项可以准确命名一个事物?

我应该如何命名它才不会混淆我未来不知道背景的对话者?

根据我的经验,最常用的术语是 Staging Area


证据:

  • 执行git命令时,文件和文件夹在Git系统中被称为StagedUnstaged
  • 根据我的观察:大多数开发人员在开始使用 Git 时只阅读 Getting Started - Git Basics 文档。本文档将其称为 Staging Area.
  • 作为一个经常使用 Git 并经常被大量使用它的人包围的人,我遇到的大多数开发人员都将其称为 Staging Area

我同意@Harmelodic 的观点……"Staging area" 这个词可能是最常用和直接的。

例如,当使用git-add命令时,你可以说你是"staging"内容。

术语 index 在 Git 的开发早期使用过,但已更改。

This 是一个很好的历史线索。

片段:

Commands that pay attention to the registered content of files rather than the copies in the work tree use the option name "--cached". This is mostly for historical reasons --- early on, it was not obvious that making the index not match the worktree was going to be useful.

...

"cache" was an old name (and still established name in-use in the code) for the index...cached to mean "look only at what is recorded in the index".

...

Originally, the way to say "what is in the current working tree for this path is what I want to have in the next commit" was "update-index". "What I want to have in the next commit" is "the index", and the operation is about "updating" that "What I want to have...", so the name of the command made perfect sense. "update-index" had a safety valve to prevent careless invocation of "update-index *" to add all the cruft in the working tree (there wasn't any .gitignore mechanism in the Porcelain nor in the plumbing) and by default affected only the paths that are already in the index. You needed to say "update-index --add" to include paths that are not in the index.

A more user friendly Porcelain "git add" was later implemented in terms of "update-index --add", but originally it was to add new paths; updating the contents was still done via "update-index" interface.

...

In short, "stage" is an unessential synonym that came much later

使用 Git 2.30.1(2021 年第一季度),文档现在关于基于“cache”的“索引”同义词更加清晰:它们已过时并已从所述文档中清除。

参见 commit b356d23 (08 Jan 2021) by Utku Gultopu (ugultopu)
(由 Junio C Hamano -- gitster -- in commit eecc5f0 合并,2021 年 1 月 15 日)

doc: remove "directory cache" from man pages

Signed-off-by: Utku Gultopu

"directory cache" (or "directory cache index", "cache") are obsolete terms which have been superseded by "index".
Keeping them in the documentation may be a source of confusion.
This commit replaces them with the current term, "index", on man pages.

git ls-files 现在包含在其 man page 中:

This merges the file listing in the index with the actual working directory list, and shows different combinations of the two.

git update-index 现在包含在其 man page 中:

Modifies the index.
Each file mentioned is updated into the index and any 'unmerged' or 'needs updating' state is cleared.