Git: What is exactly a 'working tree'? Is the same as 'working directory'?

一笑奈何 提交于 2020-01-13 07:01:26

问题


I am reading lots of documentation about Git and recently I have been looking for "working tree" concept, but I don't understand what exactly a "working tree" is.

I have found this description: What is a working tree? that seems to be the easiest to understand. But I don't fully understand it.

In the link I can read:

The Working Tree in Git is a directory (and its files and subdirectories) on your file system

So as far I can understand, the working tree is a folder on my computer. Right? Which folder exactly?

The explanation follows...

that is associated with a repository.

The term repository in the explanation is refering to the local repository as anyone can see in the following picture (the blue-green rectangle)?

Looking for similar questions here, in stackoverflow, I have found this: Working tree vs working directory

The second answer, answered by Greg, says:

Working tree means the directory that contains the .git folder, including all sub directories and files.

So I understand that working tree is the same as the working directory. Right? I mean, the directory I have the source code of my project, for example C:\Richard\Projects\Calc\ that is where I execute the command git init (inside \Calc).

Is my understanding correct?


回答1:


The offical glossary defines a working tree as:

The tree of actual checked out files.
The working tree normally contains the contents of the HEAD commit’s tree, plus any local changes that you have made but not yet committed.

It does not mention "working directory".

I mean, the directory I have the source code of my project, for example C:\Richard\Projects\Calc\ that is where I execute the command git init (inside \Calc).

Not always.

A working tree does not always have a .git in it:

  • either because the environment variable GIT_DIR is set (and references the actual path of the .git subfolder, which can be anywhere else)

  • or because you have used the git worktree command, which allows you to checkout multiple branches in multiple separate working directories, from one cloned repository: see "Multiple working directories with Git?".

But, as illustrated by that last command, "working directory" is used as a synonym from "working tree".

The second is preferred: in the very beginning of Git, commit 2a29da7 (Git v0.99.5, Aug. 2005), Junio C. Hamano mentioned:

Use "working tree", "object name", "repository" as the canonical term consistently.



来源:https://stackoverflow.com/questions/59092175/git-what-is-exactly-a-working-tree-is-the-same-as-working-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!