.git 文件夹是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29217859/
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
What is the .git folder?
提问by Omega
What is the folder called .git
?
文件夹叫.git
什么?
It's created in a repository. What is contained within it and why is created?
它是在存储库中创建的。其中包含什么以及为什么创建?
回答by Avinash Ranjan
The .git
folder contains all the information that is necessary for your project in version control and all the information about commits, remote repository address, etc. All of them are present in this folder. It also contains a log that stores your commit history so that you can roll back to history.
该.git
文件夹包含您的项目在版本控制中所需的所有信息以及有关提交、远程存储库地址等的所有信息。所有这些信息都存在于该文件夹中。它还包含一个存储提交历史的日志,以便您可以回滚到历史。
For more info, you can check the official website of git.
回答by GraceMeng
.git is initialized by git init
.
.git 由 .git 初始化git init
。
.git contains all information required for version control. If you want to clone your repo, copy .git is enough.
.git 包含版本控制所需的所有信息。如果你想克隆你的仓库,复制 .git 就足够了。
4 sub-directories:
4个子目录:
- hooks/ : example scripts
- info/ :
exclude
file for ignored patterns - objects/ : all "objects"
- refs/ : pointers to commit objects
- hooks/ : 示例脚本
- info/ :
exclude
忽略模式的文件 - 对象/:所有“对象”
- refs/ : 指向提交对象的指针
4 files:
4个文件:
- HEAD : current branch
- config : configuration options
- description
- index : staging area
- HEAD : 当前分支
- config : 配置选项
- 描述
- 索引 : 集结区
Here "object" includes:
这里的“对象”包括:
- blobs(files)
- trees(directories)
- commits(reference to a tree, parent commit, etc)
- 斑点(文件)
- 树(目录)
- 提交(对树的引用、父提交等)
回答by timhc22
This explanation should help beginners to understand the .git
folder.
这个解释应该有助于初学者理解.git
文件夹。
The .git
folder is a bit like a magic hat into which you put your current magic show.
该.git
文件夹有点像魔术帽,您可以将当前的魔术表演放入其中。
When you create a new git repository (git init
), everything you organise into a show format is put inside this magic hat and can be 'pulled out' whenever, wherever you want.
当您创建一个新的 git 存储库 ( git init
) 时,您组织成表演格式的所有内容都放在这个魔术帽中,并且可以随时随地“拉出”。
After pulling everything out, you can throw everything away when you are finished with the show (i.e. all your files except the .git
folder), and you can always pull out exactly the same show at a later date. (As each new show is simply a clone of what is inside the hat).
拉出所有内容后,您可以在完成节目时扔掉所有内容(即除了.git
文件夹之外的所有文件),并且您始终可以在以后拉出完全相同的节目。(因为每个新节目都只是帽子内部内容的克隆)。
If you send someone JUST the .git
folder, they can always pull out your project files into the same structure (show format) as you put them in.
如果您仅将.git
文件夹发送给某人,他们始终可以将您的项目文件提取到与您放入时相同的结构(显示格式)中。
git add
tells the .git
folder what is able to be pulled out e.g. a rabbit wearing a tuxedo and holding a cane (or a single file or whole menu bar on your website).
git add
告诉.git
文件夹什么可以拉出,例如一只穿着燕尾服并拿着手杖的兔子(或网站上的单个文件或整个菜单栏)。
git rm
tells the .git
folder to stop allowing something to be pulled out of the hat e.g. imagine if you no longer wanted the rabbit to be part of your magic show. (Important to note, that you can still recover a previous version of your show, which would include the rabbit (your 1999 version of your blog with Comic Sans), if you really wanted, but your current show would not include the rabbit if you used git rm
).
git rm
告诉.git
文件夹停止允许从帽子中拉出东西,例如想象一下,如果您不再希望兔子成为魔术表演的一部分。(重要的是要注意,如果您真的想要,您仍然可以恢复您的节目的先前版本,其中包括兔子(您 1999 年版本的带有 Comic Sans 的博客),但如果您愿意,您当前的节目将不包括兔子使用git rm
)。
回答by Rajni Kewlani
The .git
folder is the directory which is created when you do git init
(in the case of a new project) or you do git clone
(in the case of pulling a project from somewhere else). This is the "thing" which makes your project a "git" repository. Without .git
, your project is a local project and not a git project, that means you cannot perform any git operations.
该.git
文件夹是在您执行git init
(在新项目的情况下)或执行git clone
(在从其他地方提取项目的情况下)时创建的目录。这是使您的项目成为“git”存储库的“东西”。如果没有.git
,您的项目是本地项目而不是 git 项目,这意味着您无法执行任何 git 操作。
git stores the metadata and object database for the project in this directory like:
git 将项目的元数据和对象数据库存储在此目录中,例如:
- Remote information (to which remote server your project is connected)
- History of all local commits
- Branch information (on which branch is your current project state (HEAD) pointing to)
- All logs of all local commits you have ever made (including revert changes)
- 远程信息(您的项目连接到哪个远程服务器)
- 所有本地提交的历史记录
- 分支信息(您当前的项目状态 (HEAD) 指向哪个分支)
- 您所做的所有本地提交的所有日志(包括还原更改)
To know more, check the official documentation from git: https://git-scm.com/book/en/v1/Git-Basics-Getting-a-Git-Repository
要了解更多信息,请查看 git 的官方文档:https: //git-scm.com/book/en/v1/Git-Basics-Getting-a-Git-Repository
回答by Aaron_ab
Basiclly, it means your dir is handled by Git (Git repository). If you move it somewhere else (or delete it), you'll face something like:
基本上,这意味着您的目录由 Git(Git 存储库)处理。如果您将其移动到其他地方(或将其删除),您将面临以下情况:
fatal: Not a git repository (or any of the parent directories): .git
致命:不是 git 存储库(或任何父目录):.git
every time you use 'git *' command there.
每次你在那里使用 'git *' 命令时。
You can move the .gitdirectory somewhere else using:
您可以使用以下命令将.git目录移动到其他位置:
git --git-dir=/myproject_path/myproject.git log --oneline
git --git-dir=/myproject_path/myproject.git log --oneline
Or:
或者:
export GIT_DIR=/myproject_path/myproject.git
导出 GIT_DIR=/myproject_path/myproject.git
But i don't recommend doing it. Pay attention that it is only 1 folder, unlike SVN.
但我不建议这样做。注意它只有 1 个文件夹,与 SVN 不同。
It holds all relevant info for GIT to handle your code, like the position of the HEAD, hooks to apply before/after commit/push and some other files.
它包含 GIT 处理代码的所有相关信息,例如 HEAD 的位置、在提交/推送之前/之后应用的钩子以及其他一些文件。
Maybe most "famous" file inside is the configfile which holds all your branches info.
也许里面最“著名”的文件是包含所有分支信息的配置文件。
Recommend to read heremore info.
建议在这里阅读更多信息。
回答by Qwerty
what's inside your .git
directory
你的.git
目录里有什么
If you were curious — ? —, this resource might be of help
如果你好奇——?—,这个资源可能有帮助
http://gitready.com/advanced/2009/03/23/whats-inside-your-git-directory.html
http://gitready.com/advanced/2009/03/23/whats-inside-your-git-directory.html
The basic structure looks like this:
. |-- COMMIT_EDITMSG |-- FETCH_HEAD |-- HEAD |-- ORIG_HEAD |-- branches |-- config |-- description |-- hooks | |-- applypatch-msg | |-- commit-msg | |-- post-commit
... continues on the site
基本结构如下所示:
. |-- COMMIT_EDITMSG |-- FETCH_HEAD |-- HEAD |-- ORIG_HEAD |-- branches |-- config |-- description |-- hooks | |-- applypatch-msg | |-- commit-msg | |-- post-commit
... 继续在网站上