git:深挖 .git文件夹

.git目录树

.
└── .git
    │  
    │  
    ├── branches
    │  
    │  
    ├── COMMIT_EDITMSG    # 保存最新的commit message,Git系统不会用到这个文件,只是给用户一个参考。
    │  
    │  
    ├── config    # 仓库的配置文件。
    │  
    │  
    ├── description    # 仓库的描述信息,主要给gitweb等git托管系统使用。
    │  
    │  
    ├── HEAD    # 包含了一个分支的引用,通过这个文件Git可以得到下一次commit的parent,可以理解为指针。
    │  
    │  
    ├── hooks    # 存放一些shell脚本,可以设置特定的git命令后触发相应的脚本。
    │   │   
    │   ├── applypatch-msg.sample
    │   ├── commit-msg.sample
    │   ├── post-update.sample
    │   ├── pre-applypatch.sample
    │   ├── pre-commit.sample
    │   ├── prepare-commit-msg.sample
    │   ├── pre-push.sample
    │   ├── pre-rebase.sample
    │   └── update.sample
    │  
    │
    ├── index    # 二进制暂存区(stage)。
    │  
    │  
    ├── info    # 仓库的其他信息。
    │   │  
    │   └── exclude
    │  
    │ 
    ├── logs    # 保存所有更新的引用记录。
    │   │ 
    │   ├── HEAD    # 最后一次的提交信息。
    │   └── refs
    │       ├── heads
    │       │   └── master
    │       └── remotes
    │           └── origin
    │               ├── HEAD
    │               └── master
    │  
    │ 
    ├── objects    # 所有对象的存储,对象的SHA1哈希值的前两位是文件夹名称,后38位作为对象文件名。
    │   │  
    │   ├── [0-9A-F][0-9A-F]
    │   │   └── dbc3be082ca20a9d032c25623871f503e5797c
    │   ├── info    # 记录对象存储的附加信息
    │   └── pack    # 以压缩形式(.pack)存储许多对象的文件,附带索引文件(.idx)以允许它们被随机访问。
    │       ├── pack-a62b75ba184ef8686604b5f2f366f958022a2fb5.idx
    │       └── pack-a62b75ba184ef8686604b5f2f366f958022a2fb5.pack
    │  
    │  
    └── refs    # 具体的引用,Reference Specification。
        │
        ├── heads    # 记录commit分支的树根
        │   └── master    # 标识了本地项目中的master分支指向的当前commit的哈希值。
        ├── remotes    # 记录从远程仓库copy来的commit分支的树根
        │   └── origin
        │       ├── HEAD
        │       └── master    # 标识了远端项目中的master分支指向的当前commit的哈希值。
        └── tags    # 记录任何对象名称(不一定是提交对象或指向提交对象的标签对象)。

.git目录树具体变更

  新建一个仓库时:

.
└── .git
    ├── branches
    ├── config
    ├── description
    ├── HEAD
    ├── hooks
    │   ├── applypatch-msg.sample
    │   ├── commit-msg.sample
    │   ├── post-update.sample
    │   ├── pre-applypatch.sample
    │   ├── pre-commit.sample
    │   ├── prepare-commit-msg.sample
    │   ├── pre-push.sample
    │   ├── pre-rebase.sample
    │   └── update.sample
    ├── info
    │   └── exclude
    ├── objects
    │   ├── info
    │   └── pack
    └── refs
        ├── heads
        └── tags

10 directories, 13 files

  第一次 git commit 过后:

.
└── .git
    ├── branches
    ├── COMMIT_EDITMSG
    ├── config
    ├── description
    ├── HEAD
    ├── hooks
    │   ├── applypatch-msg.sample
    │   ├── commit-msg.sample
    │   ├── post-update.sample
    │   ├── pre-applypatch.sample
    │   ├── pre-commit.sample
    │   ├── prepare-commit-msg.sample
    │   ├── pre-push.sample
    │   ├── pre-rebase.sample
    │   └── update.sample
    ├── info
    │   └── exclude
    ├── objects
    │   ├── info
    │   └── pack
    └── refs
        ├── heads
        └── tags

10 directories, 14 files

  可以看到增加了 COMMIT_EDITMSG 文件。


查看git仓库的布局:

git help gitrepository-layout

  输出:

GITREPOSITORY-LAYOU(5)            Git Manual            GITREPOSITORY-LAYOU(5)

NAME
       gitrepository-layout - Git Repository Layout

SYNOPSIS
       $GIT_DIR/*

DESCRIPTION
       A Git repository comes in two different flavours:

       ·   a .git directory at the root of the working tree;

       ·   a <project>.git directory that is a bare repository (i.e. without
           its own working tree), that is typically used for exchanging
           histories with others by pushing into it and fetching from it.

       Note: Also you can have a plain text file .git at the root of your
       working tree, containing gitdir: <path> to point at the real directory
       that has the repository. This mechanism is often used for a working
       tree of a submodule checkout, to allow you in the containing
       superproject to git checkout a branch that does not have the submodule.
       The checkout has to remove the entire submodule working tree, without
       losing the submodule repository.

       These things may exist in a Git repository.

       objects
           Object store associated with this repository. Usually an object
           store is self sufficient (i.e. all the objects that are referred to
           by an object found in it are also found in it), but there are a few
           ways to violate it.

            1. You could have an incomplete but locally usable repository by
               creating a shallow clone. See git-clone(1).

            2. You could be using the objects/info/alternates or
               $GIT_ALTERNATE_OBJECT_DIRECTORIES mechanisms to borrow objects
               from other object stores. A repository with this kind of
               incomplete object store is not suitable to be published for use
               with dumb transports but otherwise is OK as long as
               objects/info/alternates points at the object stores it borrows
               from.

       objects/[0-9a-f][0-9a-f]
           A newly created object is stored in its own file. The objects are
           splayed over 256 subdirectories using the first two characters of
           the sha1 object name to keep the number of directory entries in
           objects itself to a manageable number. Objects found here are often
           called unpacked (or loose) objects.

       objects/pack
           Packs (files that store many object in compressed form, along with
           index files to allow them to be randomly accessed) are found in
           this directory.

       objects/info
           Additional information about the object store is recorded in this
           directory.

       objects/info/packs
           This file is to help dumb transports discover what packs are
           available in this object store. Whenever a pack is added or
           removed, git update-server-info should be run to keep this file
           up-to-date if the repository is published for dumb transports.  git
           repack does this by default.

       objects/info/alternates
           This file records paths to alternate object stores that this object
           store borrows objects from, one pathname per line. Note that not
           only native Git tools use it locally, but the HTTP fetcher also
           tries to use it remotely; this will usually work if you have
           relative paths (relative to the object database, not to the
           repository!) in your alternates file, but it will not work if you
           use absolute paths unless the absolute path in filesystem and web
           URL is the same. See also objects/info/http-alternates.

       objects/info/http-alternates
           This file records URLs to alternate object stores that this object
           store borrows objects from, to be used when the repository is
           fetched over HTTP.

       refs
           References are stored in subdirectories of this directory. The git
           prune command knows to preserve objects reachable from refs found
           in this directory and its subdirectories.

       refs/heads/name
           records tip-of-the-tree commit objects of branch name

       refs/tags/name
           records any object name (not necessarily a commit object, or a tag
           object that points at a commit object).

       refs/remotes/name
           records tip-of-the-tree commit objects of branches copied from a
           remote repository.

       refs/replace/<obj-sha1>
           records the SHA-1 of the object that replaces <obj-sha1>. This is
           similar to info/grafts and is internally used and maintained by
           git-replace(1). Such refs can be exchanged between repositories
           while grafts are not.

       packed-refs
           records the same information as refs/heads/, refs/tags/, and
           friends record in a more efficient way. See git-pack-refs(1).

       HEAD
           A symref (see glossary) to the refs/heads/ namespace describing the
           currently active branch. It does not mean much if the repository is
           not associated with any working tree (i.e. a bare repository), but
           a valid Git repository must have the HEAD file; some porcelains may
           use it to guess the designated "default" branch of the repository
           (usually master). It is legal if the named branch name does not
           (yet) exist. In some legacy setups, it is a symbolic link instead
           of a symref that points at the current branch.

           HEAD can also record a specific commit directly, instead of being a
           symref to point at the current branch. Such a state is often called
           detached HEAD.  See git-checkout(1) for details.

       branches
           A slightly deprecated way to store shorthands to be used to specify
           a URL to git fetch, git pull and git push. A file can be stored as
           branches/<name> and then name can be given to these commands in
           place of repository argument. See the REMOTES section in git-
           fetch(1) for details. This mechanism is legacy and not likely to be
           found in modern repositories.

       hooks
           Hooks are customization scripts used by various Git commands. A
           handful of sample hooks are installed when git init is run, but all
           of them are disabled by default. To enable, the .sample suffix has
           to be removed from the filename by renaming. Read githooks(5) for
           more details about each hook.

       index
           The current index file for the repository. It is usually not found
           in a bare repository.

       info
           Additional information about the repository is recorded in this
           directory.

       info/refs
           This file helps dumb transports discover what refs are available in
           this repository. If the repository is published for dumb
           transports, this file should be regenerated by git
           update-server-info every time a tag or branch is created or
           modified. This is normally done from the hooks/update hook, which
           is run by the git-receive-pack command when you git push into the
           repository.

       info/grafts
           This file records fake commit ancestry information, to pretend the
           set of parents a commit has is different from how the commit was
           actually created. One record per line describes a commit and its
           fake parents by listing their 40-byte hexadecimal object names
           separated by a space and terminated by a newline.

       info/exclude
           This file, by convention among Porcelains, stores the exclude
           pattern list.  .gitignore is the per-directory ignore file.  git
           status, git add, git rm and git clean look at it but the core Git
           commands do not look at it. See also: gitignore(5).

       info/sparse-checkout
           This file stores sparse checkout patterns. See also: git-read-
           tree(1).

       remotes
           Stores shorthands for URL and default refnames for use when
           interacting with remote repositories via git fetch, git pull and
           git push commands. See the REMOTES section in git-fetch(1) for
           details. This mechanism is legacy and not likely to be found in
           modern repositories.

       logs
           Records of changes made to refs are stored in this directory. See
           git-update-ref(1) for more information.

       logs/refs/heads/name
           Records all changes made to the branch tip named name.

       logs/refs/tags/name
           Records all changes made to the tag named name.

       shallow
           This is similar to info/grafts but is internally used and
           maintained by shallow clone mechanism. See --depth option to git-
           clone(1) and git-fetch(1).

       modules
           Contains the git-repositories of the submodules.

SEE ALSO
       git-init(1), git-clone(1), git-fetch(1), git-pack-refs(1), git-gc(1),
       git-checkout(1), gitglossary(7), The Git User’s Manual[1]

GIT
       Part of the git(1) suite.

NOTES
        1. The Git User’s Manual
           file:///usr/share/doc/git/html/user-manual.html

Git 1.9.1                         03/19/2014            GITREPOSITORY-LAYOU(5)


Ref:



本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏向治洪

svn错误对照表

#, c-format msgid "Destination '%s' is not a directory" msgstr "目的 “%s” 不是目录" ...

3315
来自专栏LEo的网络日志

python i18n实现

3787
来自专栏技术墨客

Spring核心——数据校验

在Java数据校验详解中详细介绍了Java数据校验相关的功能(简称Bean Validation,涵盖JSR-303、JSR-349、JSR-380),本文将在...

801
来自专栏IT笔记

SpringBoot开发案例之整合Dubbo消费者

有人卖就有人买,显然是亘古不变的真理,前两篇讲解了SpringBoot+Dubbo的提供者的几种暴露方式,这篇跟大家分享一下消费者如何去订阅属于自己的服务。 相...

3515
来自专栏从零开始学自动化测试

appium+python自动化60-appium命令行参数

许多Appium 1.5服务器参数已被弃用,以支持—default-capabilities标志。

2141
来自专栏一枝花算不算浪漫

ActiveMQ的介绍及使用实例.

3657
来自专栏xingoo, 一个梦想做发明家的程序员

如何在Java应用中提交Spark任务?

最近看到有几个Github友关注了Streaming的监控工程——Teddy,所以思来想去还是优化下代码,不能让别人看笑话啊。于是就想改一下之前觉得最丑陋的一...

6416
来自专栏黑泽君的专栏

day32_Hibernate学习笔记_04

  缓存(Cache):是计算机领域非常通用的概念。它介于应用程序和永久性数据存储源(如硬盘上的文件或者数据库)之间,其作用是降低应用程序直接读写硬盘(永久性数...

982
来自专栏XAI

SpringMVC+MongoDB+Maven整合(微信回调Oauth授权)

个人小程序。里面是基于百度大脑 腾讯优图做的人脸检测。是关于人工智能的哦。 2017年第一篇自己在工作中的总结文档。土豪可以打赏哦。 https://git.o...

8097
来自专栏yukong的小专栏

​【SpringBoot2.0系列06】SpringBoot之多数据源动态切换数据源

【SpringBoot2.0系列02】SpringBoot之使用Thymeleaf视图模板

7327

扫码关注云+社区

领取腾讯云代金券