什么是.git文件夹? [英] What is the .git folder?

查看:160
本文介绍了什么是.git文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请有人向我解释文件夹.git是什么?



它是在存储库中创建的,包含的内容以及为什么创建?

解决方案

我最喜欢Git的一件事情是它将所有信息保存在一个地方: .git 在你的项目根目录下。如果你还没有在周围挖掘它,请不要担心!其中有很多好东西。让我们来看看重要的文件和文件夹,并试图更好地理解底层的情况。



基本结构如下所示:


| - COMMIT_EDITMSG
| - FETCH_HEAD
| - HEAD
| - ORIG_HEAD
| - 分支
| - config
| - 描述
| - 钩子
| | - applypatch-msg
| | - commit-msg
| | - 后提交
| | - 收到
| | - 更新后
| | - pre-applypatch
| | - 预先提交
| | - 预先兑换
| | - prepare-commit-msg
| ` - 更新
| - 索引
| - 信息
| ` - 排除
| - 记录
| | - HEAD
| ` - refs
| - objects
` - refs
| - heads
| - 远程
| - 藏匿
` - - - tags




  • COMMIT_EDITMSG :这是最后一个提交的消息。它完全没有被Git实际使用,但它在那里提供后主要供您参考。

  • config :包含设置为这个存储库。具体配置变量可以在这里转储(甚至可以别名!)该文件最常用于定义遥控器的存在位置和一些核心设置,例如您的存储库是否裸露。
  • code>:如果您使用 gitweb 或启动 git instaweb ,这会在您查看您的存储库或所有版本化存储库列表时显示出来。
  • FETCH_HEAD :在最后一个 git fetch

  • HEAD :您正在查看的当前裁判。在大多数情况下,它可能是 refs / heads / master

  • index :The使用元数据临时区域,例如时间戳,文件名称以及已由Git包装的文件的SHA。
  • 而不是你仓库中的权威清单( refs 文件夹有真正的!)看看gitster的评论,看看更多关于这方面的信息。
  • ORIG_HEAD :进行合并时,这是您合并到的分支的SHA。

  • MERGE_HEAD :进行合并时,这是您要合并的分支的SHA。
  • MERGE_MODE :用于在最初为 git merge 赋予 git commit 合并冲突和单独的 git c ommit 需要结束它。目前 - no-ff 是通过这种方式传递的唯一约束。
  • MERGE_MSG :枚举当前合并期间发生的冲突。

  • RENAMED-REF :仍在尝试追踪这一个。从基本的grep到源代码,似乎这个文件与保存引用时的错误有关。



还有很多目录:




  • 钩子:一个快速成为您最好的朋友的目录:在使用Git的某些时候执行的脚本,例如提交之后或重新绑定之前。一系列的文章将围绕钩子展开。

  • info :除了排除存在于其中的文件。我们之前在忽略文件文章中看到过这一点,但作为提醒,您可以使用此文件忽略此项目的文件,但要小心!它没有像 .gitignore 文件那样的版本。

  • logs :包含不同分支的历史记录。似乎主要用于 reflog 命令。

  • objects :Git的blob内部仓库,全部由SHA索引。 code> rebase-apply : rebasing git am 。如果你勇敢的话,你可以深入研究它的补丁文件。
  • :存储在您的存储库中的所有ref的主副本,无论它们是用于存储,标记,远程跟踪分支还是本地分支。


当混淆Git内部时,只需要一句智慧:确保你知道你在做什么,如果没有,请备份!乱搞配置文件或钩子非常简单,但如果我不需要,我不会在数据存储区中进行探测。如果由于某种原因,您是正常工作流程的一部分,那么您可能会犯这种错误。



关于Git的内部还有很多我们还没有涉及的内容。最好的指南之一是 Git社区书,当然,您也可以为你自己下载源代码并看一看。

Please can someone explain to me what is the folder ".git" ?

It's created on the repository and what is contained and why is created?

解决方案

One of the things I like best about Git is that it keeps all of its information in one place: your .git directory in your project’s root. If you haven’t been digging around it yet, don’t fret! There’s plenty of goodies to be had within it. Let’s take a look into the important files and folders and try to get a better sense of what’s going on under the hood.

The basic structure looks like this:

.
|-- COMMIT_EDITMSG
|-- FETCH_HEAD
|-- HEAD
|-- ORIG_HEAD
|-- branches
|-- config
|-- description
|-- hooks
|   |-- applypatch-msg
|   |-- commit-msg
|   |-- post-commit
|   |-- post-receive
|   |-- post-update
|   |-- pre-applypatch
|   |-- pre-commit
|   |-- pre-rebase
|   |-- prepare-commit-msg
|   `-- update
|-- index
|-- info
|   `-- exclude
|-- logs
|   |-- HEAD
|   `-- refs
|-- objects
`-- refs
    |-- heads
    |-- remotes
    |-- stash
    `-- tags

  • COMMIT_EDITMSG: This is the last commit’s message. It’s not actually used by Git at all, but it’s there mostly for your reference after you made a commit.
  • config: Contains settings for this repository. Specific configuration variables can be dumped in here (and even aliases!) What this file is most used for is defining where remotes live and some core settings, such as if your repository is bare or not.
  • description: If you’re using gitweb or firing up git instaweb, this will show up when you view your repository or the list of all versioned repositories.
  • FETCH_HEAD: The SHAs of branch/remote heads that were updated during the last git fetch
  • HEAD: The current ref that you’re looking at. In most cases it’s probably refs/heads/master
  • index: The staging area with meta-data such as timestamps, file names and also SHAs of the files that are already wrapped up by Git.
  • packed-refs: Packs away dormant refs, this is not the definitive list of refs in your repository (the refs folder has the real ones!) Take a look at gitster’s comment to see more information on this.
  • ORIG_HEAD: When doing a merge, this is the SHA of the branch you’re merging into.
  • MERGE_HEAD: When doing a merge, this is the SHA of the branch you’re merging from.
  • MERGE_MODE: Used to communicate constraints that were originally given to git merge to git commit when a merge conflicts, and a separate git commit is needed to conclude it. Currently --no-ff is the only constraints passed this way.
  • MERGE_MSG: Enumerates conflicts that happen during your current merge.
  • RENAMED-REF: Still trying to track this one down. From a basic grep through the source, it seems like this file is related to errors when saving refs.

There’s plenty of directories as well:

  • hooks: A directory that will fast become your best friend: this contains scripts that are executed at certain times when working with Git, such as after a commit or before a rebase. An entire series of articles will be coming about hooks.
  • info: Relatively uninteresting except for the exclude file that lives inside of it. We’ve seen this before in the ignoring files article, but as a reminder, you can use this file to ignore files for this project, but beware! It’s not versioned like a .gitignore file would be.
  • logs: Contains history for different branches. Seems to be used mostly with the reflog command.
  • objects: Git’s internal warehouse of blobs, all indexed by SHAs.
  • rebase-apply: The workbench for rebasing and for git am. You can dig into its patch file when it does not apply cleanly if you’re brave.
  • refs: The master copy of all refs that live in your repository, be they for stashes, tags, remote tracking branches, or local branches.

Just one word of wisdom when messing around with Git internals: make sure you know what you’re doing, and if not, have a backup! Messing around with the config files or hooks is pretty simple but I wouldn’t go spelunking in the datastore if I didn’t have to. If for some reason you are as part of your normal workflow, you might be doing it wrong.

There’s plenty more about the internals of Git that we haven’t covered yet. One of the best guides is the Git Community Book, and of course, you can just download the source for yourself and take a look.

这篇关于什么是.git文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆