Git:“工作目录”究竟在哪里?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36201342/
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
Git: Where exactly is the "working directory"?
提问by shenkwen
I am going through some Git tutorials. The concept of a "working directory" keeps being mentioned, however, none of the tutorials or documents I read points out where or what this "working directory" is.
我正在学习一些 Git 教程。“工作目录”的概念不断被提及,然而,我读过的教程或文档都没有指出这个“工作目录”在哪里或什么。
I have thought that it was actually the .git
's parent directory, a.k.a the directory I run git init
in. But the video tutorial I am watching talks about the state of nothing to commitand "working directory clean":
我认为它实际上是.git
的父目录,也就是我运行的目录git init
。但是我正在观看的视频教程讨论了无提交状态和“工作目录清理”:
In fact you can actually make a copy of the repository, and make that copy so that it does not have a working directory, this is actually called the bare clone. This is actually what GitHub uses.
实际上,您实际上可以制作存储库的副本,并制作该副本以使其没有工作目录,这实际上称为裸克隆。这实际上是 GitHub 使用的。
If my understanding of the "working directory" is correct, how can a repository not have a "working directory"? And what does it mean, when it says that GitHub uses a "bare clone"?
如果我对“工作目录”的理解是正确的,那么仓库怎么可能没有“工作目录”呢?当它说 GitHub 使用“裸克隆”时,这是什么意思?
回答by jacmoe
This should hopefully clear things up for us:
这应该有望为我们解决问题:
What is the difference between a repository created using the git init command and the git init --bare command?
Repositories created with the git init command are called working directories. In the top level folder of the repository you will find two things:
A .git subfolder with all the git related revision history of your repo A working tree, or checked out copies of your project files.
Repositories created with git init --bare are called bare repos. They are structured a bit differently from working directories. First off, they contain no working or checked out copy of your source files. And second, bare repos store git revision history of your repo in the root folder of your repository instead of in a .git subfolder. Note… bare repositories are customarily given a .git extension.
使用 git init 命令和 git init --bare 命令创建的存储库有什么区别?
使用 git init 命令创建的存储库称为工作目录。在存储库的顶级文件夹中,您会发现两件事:
A .git subfolder with all the git related revision history of your repo A working tree, or checked out copies of your project files.
使用 git init --bare 创建的存储库称为裸存储库。它们的结构与工作目录略有不同。首先,它们不包含源文件的工作或检出副本。其次,裸仓库将仓库的 git 修订历史存储在仓库的根文件夹中,而不是在 .git 子文件夹中。注意……裸仓库通常有一个 .git 扩展名。
Taken from John Saints - What is a bare git repository?
A bare git clone does not contain a working directory of checked out code, in other words.
Think of it as just the .git
directory (the Git database) without anything else.
换句话说,裸 git clone 不包含检出代码的工作目录。
将其视为.git
没有其他任何内容的目录(Git 数据库)。
回答by Som Bhattacharyya
Its is wherever you have checkout the project. For example the directory within which you have checked out a branch of your project. Its is typically the folder that contains the .git
folder. That is the working directory. When you make changes to files in your checked out branch you make changes to the working directory. At this point the working directory has uncommitted changes. So initially when you haven't made any commits the working directory will be clean as there are no changes.
它是您签出项目的任何地方。例如,您在其中检出项目分支的目录。它通常是包含.git
文件夹的文件夹。那是工作目录。当您更改检出分支中的文件时,您也会更改工作目录。此时工作目录有未提交的更改。因此,最初当您没有进行任何提交时,工作目录将是干净的,因为没有任何更改。
回答by Babajide Apata
The working directory is simply, your current local directory that you are working on. e.g if you have master, dev and yourname-devas your remote branches, if you checkoutfrom devto yourname-dev, yourname-devis now your working directory if you checkout from this (yourname-dev) working directory to another say dev, devis now your new working directory
工作目录很简单,就是您正在处理的当前本地目录。例如,如果你有master、dev 和 yourname-dev作为你的远程分支,如果你从dev结帐到yourname-dev,如果你从这个(yourname-dev)工作目录结帐到另一个说dev,yourname-dev现在是你的工作目录, dev现在是你的新工作目录
回答by Michael Ma
According to the documentation:
根据文档:
Finally, you have your working directory. The other two trees store their content in an efficient but inconvenient manner, inside the .git folder. The Working Directory unpacks them into actual files, which makes it much easier for you to edit them. Think of the Working Directory as a sandbox, where you can try changes out before committing them to your staging area (index) and then to history.
最后,你有你的工作目录。另外两棵树以一种高效但不方便的方式将它们的内容存储在 .git 文件夹中。工作目录将它们解包为实际文件,这使您更容易编辑它们。将工作目录视为沙箱,您可以在其中尝试更改,然后再将更改提交到临时区域(索引),然后提交到历史记录。
回答by Harmelodic
To kind of combine the two other answers:
结合其他两个答案:
As stated in the Git Documentation:
The working directory is a single checkout of one version of the project.
工作目录是项目的一个版本的单一检出。
This essentially means if you checkout a branch (e.g. master) and are sat on a particular commit (e.g. HEAD), your working directory is the "umbrella" term for all your files and folders.
这实质上意味着,如果您签出一个分支(例如 master)并处于特定的提交(例如 HEAD)上,那么您的工作目录就是所有文件和文件夹的“总括”术语。
It isn'ta particular directory/folder though. The working directory covers all directories, files...everything.
I mention this because when you want to commit some files, those files will be in the working directory and you'll need to stagethem (using git add
) before committing them (using git commit
).
虽然它不是特定的目录/文件夹。工作目录涵盖所有目录、文件……一切。
我提这个,因为当你要提交一些文件,这些文件将在工作目录,你需要阶段他们(使用git add
(使用提交之前)git commit
)。
回答by Zeek2
Do you work directly in the local repos?
你直接在本地仓库工作吗?
When I follow Microsoft's instructions [ref. https://docs.microsoft.com/en-us/azure/devops/repos/git/clone?view=azure-devops&tabs=visual-studio], that's where I end up opening the .sln solution file. That seems wrong to me and unfortunate, because I prefer to work on code on my massive D: drive (D:\dev) rather than in C:\Users\\source\repos, where the repos are kept by default (I don't mind the local repos being kept there - it's not ideal - as long as I can work in my D:\dev area).
当我按照 Microsoft 的说明进行操作时 [ref. https://docs.microsoft.com/en-us/azure/devops/repos/git/clone?view=azure-devops&tabs=visual-studio],这就是我最终打开 .sln 解决方案文件的地方。这对我来说似乎是错误的而且很不幸,因为我更喜欢在我庞大的 D: 驱动器 (D:\dev) 上而不是在 C:\Users\\source\repos 中处理代码,默认情况下会保留 repos(我不不介意将本地存储库保存在那里 - 这并不理想 - 只要我可以在我的 D:\dev 区域工作)。