The 官方术语定义了工作树 https://git-scm.com/docs/gitglossary#def_working_tree as:
实际检出文件的树.
工作树通常包含 HEAD 提交树的内容,以及您已进行但尚未提交的任何本地更改。
它没有提到“工作目录”。
我的意思是,我的项目源代码所在的目录,例如C:\Richard\Projects\Calc\
这就是我执行命令的地方git init
(里面\Calc
).
不总是。
工作树不always have a .git
in it:
-
要么因为环境变量GIT_DIR is set https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables#_repository_locations(并引用实际路径.git
子文件夹,可以是其他任何地方)
-
或者因为您已经使用了git worktree https://git-scm.com/docs/git-worktree命令,它允许您从多个单独的工作目录中签出多个分支one克隆存储库:请参阅“Git 的多个工作目录? https://stackoverflow.com/a/30185564/6309".
但是,正如最后一个命令所示,“工作目录”用作“工作树”的同义词。
第二种是首选:在 Git 一开始,提交 2a29da7 https://github.com/git/git/commit/2a29da7c6d6103c4719c71f6cce88e853260912c(Git v0.99.5,2005 年 8 月),Junio C. Hamano 提到:
一致使用“工作树”、“对象名称”、“存储库”作为规范术语。
“工作树”和“每个工作树引用”在术语表中,但“工作树”本身不在术语表中,这一点已在 Git 2.36(2022 年第 2 季度)中得到纠正。
See commit 2df5387 https://github.com/git/git/commit/2df5387ed04159b188de65dff9654d4aae1062d2 (09 Feb 2022) by Junio C Hamano (gitster) https://github.com/gitster.
(Merged by Junio C Hamano -- gitster -- https://github.com/gitster in commit 9a1d169 https://github.com/git/git/commit/9a1d16989fd8ab14c1831e143c39d29fe9192df1, 18 Feb 2022)
glossary https://github.com/git/git/commit/2df5387ed04159b188de65dff9654d4aae1062d2:描述“工作树”
我们对“per worktree ref”有描述,但术语表中没有描述“worktree”。
不过,我们确实有“工作树”。
简单地说,“工作树”是编辑器和编译器交互的对象。
“工作树”是一种允许将一个或多个“工作树”附加到存储库并用于独立检查不同提交和分支的机制,其中不仅包括“工作树”,还包括存储库元数据,例如 HEAD、索引以支持同时使用它们。
从历史上看,我们可以互换使用这些术语,但我们一直在尝试使用“工作树”,而不是“工作树”。
术语表中大多数现有对“工作树”的引用确实主要指工作树部分,除了 HEAD 和 refs/bisect/* 等引用是每个“工作树”的,但更准确地说它们是每个“工作树”。
glossary-content
现在包含在其man page https://github.com/git/git/blob/2df5387ed04159b188de65dff9654d4aae1062d2/Documentation/glossary-content.txt#L672-L680:
worktree
一个存储库可以有零个(即裸存储库)或一个或
更多工作树附加到它。一个“工作树”由
“工作树”和存储库元数据,其中大部分是
在单个存储库的其他工作树之间共享,以及
其中一些是每个工作树单独维护的
(例如索引、HEAD 和伪引用,如 MERGE_HEAD、
每个工作树引用和每个工作树配置文件)。
因此,Git 2.36(2022 年第 2 季度)收紧了文档中围绕“工作树”和“工作树”的语言。
See commit 07d8538 https://github.com/git/git/commit/07d85380b21653b949f2777903e44aaf0fdb6c44, commit f13a146 https://github.com/git/git/commit/f13a146c81e361eab43cd095c80c01562b6016de, commit 7b21582 https://github.com/git/git/commit/7b215826f32f9fd0dc58703f012326dba6006e34, commit a777d4c https://github.com/git/git/commit/a777d4c75061f99ae16246835db9d0750ce01d4c, commit 6036be1 https://github.com/git/git/commit/6036be14581878c42158407a9f3344d63f090057, commit 5997014 https://github.com/git/git/commit/599701441e5e7853339306f56e82cb02543d53a7, commit c57bf8c https://github.com/git/git/commit/c57bf8ce9e6f41947e661fdecef3736aa816c50e, commit 23f832e https://github.com/git/git/commit/23f832e29ec20ddbded431fdf55f49dc0f54e794, commit ace5ac5 https://github.com/git/git/commit/ace5ac533a198e9bb7f634dafa8e7b10a42919c4, commit 8639705 https://github.com/git/git/commit/863970536525f071b29f2ee73ac9ac0a35b32a43, commit 92d9234 https://github.com/git/git/commit/92d92345ce5996933f5cfc357dce1e1744487b6a (23 Feb 2022) by Derrick Stolee (derrickstolee) https://github.com/derrickstolee.
(Merged by Junio C Hamano -- gitster -- https://github.com/gitster in commit aae90a1 https://github.com/git/git/commit/aae90a156de9d84cfe5e2052678d22c18ff285b2, 06 Mar 2022)
worktree https://github.com/git/git/commit/f13a146c81e361eab43cd095c80c01562b6016de:使用“工作树”而不是“工作树”
Signed-off-by: Derrick Stolee
区分“工作树”和“工作树”很有帮助。
工作树包含工作树以及附加元数据。
此元数据包括每个工作树的引用和特定于工作树的配置。
这是对 git-worktree.txt 的多次更改中的第六次,仅限于 DETAILS 部分。
git worktree
现在包含在其man page https://github.com/git/git/blob/f13a146c81e361eab43cd095c80c01562b6016de/Documentation/git-worktree.txt#L322:
每个链接的工作树在存储库中都有一个私有子目录
...
链接工作树路径的基本名称,可能附加一个
...