Gitウェアハウスdirectory.gitの詳細

  目次

1.サンプル環境

第二に、ディレクトリ構造

2.1ブランチディレクトリ

2.2COMMIT_EDITMSGファイル

2.3設定ファイル

2.4記述ファイル

2.5HEADファイル

2.6フックディレクトリ

2.7インデックスファイル

2.8情報ディレクトリ

2.9ログディレクトリ

2.10オブジェクトディレクトリ

2.11refsディレクトリ

3.参考文献


Gitがウェアハウスを作成すると、現在のウェアハウスディレクトリに.gitという名前の隠しディレクトリが作成され、ウェアハウスの構成とデータ情報が保存されます。この記事では、Gitリポジトリの基本的なディレクトリを例とともに紹介します。

1.サンプル環境

次の例はすべて、次の環境で実行されます。

システム環境: CentOS Linuxリリース7.6.1810(コア)

gitバージョン: gitバージョン1.8.3.1

リモートウェアハウス: GitHub。

第二に、ディレクトリ構造

git initコマンドを使用して、ウェアハウスを初期化します。初期ディレクトリ(.git)の構造は次のとおりです。

[root@192 testgit]# tree .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

9 directories, 13 files
[root@192 testgit]# 

 この初期化されたウェアハウスでは、ブランチdev-branchが作成されてプッシュされると、ディレクトリ構造は次のようになります。

[root@192 testgit]# tree .git/
.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
├── index
├── info
│   └── exclude
├── logs
│   ├── HEAD
│   └── refs
│       ├── heads
│       │   ├── dev-branch
│       │   └── master
│       └── remotes
│           └── origin
│               └── master
├── objects
│   ├── 2d
│   │   └── d2c71b69c837a7459f4bd9c9f7db6520731d06
│   ├── 5c
│   │   └── 7b8eda18a75e13d27c31e65a54b0abd7948510
│   ├── 77
│   │   └── cad3aecf7c2754231095598119979d62a1e1da
│   ├── info
│   └── pack
└── refs
    ├── heads
    │   ├── dev-branch
    │   └── master
    ├── remotes
    │   └── origin
    │       └── master
    └── tags

19 directories, 25 files
[root@192 testgit]# 

次に、各ディレクトリとファイルについて詳しく説明します。

2.1ブランチディレクトリ

git fetch、git pull、git pushのURLを指定するために使用される、まれにしか使用されないストレージの省略形。現在、基本的には使用されていません。

2.2COMMIT_EDITMSGファイル

大文字を小文字に変更すると、理解しやすくなります。commit_editmsg:commit edit information、送信された最新のcommit editinformationのみを記録します。次に例を示します。

[root@192 testgit]# vim README
[root@192 testgit]# git add .
[root@192 testgit]# git commit -m "modify README file"
[master 2392c4d] modify README file
 1 file changed, 2 insertions(+), 1 deletion(-)
[root@192 testgit]# git push origin master
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 315 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To [email protected]:New-World-2019/testgit.git
   3cbe67c..2392c4d  master -> master
[root@192 testgit]# cat .git/COMMIT_EDITMSG 
modify README file
[root@192 testgit]# 

上記の例では、最初にREADMEファイルを変更してからリモートにプッシュし、コミット時に「modify README file」と書き込んでから、COMMIT_EDITMSGファイルを表示し、送信時にコメントを保存します。 

2.3設定ファイル

名前を見て、現在のウェアハウスの構成情報を保存するだけです。git構成ファイルは、次の3つのレイヤーに分かれています。

  1. / etc / gitconfigファイル:各ユーザーとそのウェアハウスのシステム一般構成。
  2. 〜/ .gitconfigまたは〜/ .config / git / configファイル:現在のユーザーのウェアハウス構成。
  3. .git / configファイル(現在のウェアハウスの下):現在のユーザーの現在のウェアハウスの構成;

最下位層の優先度が最も高く、上位層の構成情報を上書きします。上記のファイルは、git configパラメーターを使用して変更できます。構成可能な情報には、ユーザー情報、http情報、ウェアハウス情報などが含まれます。

[root@192 testgit]# cat ~/.gitconfig 
[user]
        name = New-World-2019
        email = [email protected]
[http]
        postBuffer = 1048576000
        lowSpeedLimit = 0
        lowSpeedTime = 999999
[root@192 testgit]# cat .git/config 
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        url = [email protected]:New-World-2019/testgit.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
[branch "dev-branch"]
        remote = origin
        merge = refs/heads/dev-branch
[root@192 testgit]# git config --list
user.name=New-World-2019
[email protected]
http.postbuffer=1048576000
http.lowspeedlimit=0
http.lowspeedtime=999999
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
[email protected]:New-World-2019/testgit.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
branch.dev-branch.remote=origin
branch.dev-branch.merge=refs/heads/dev-branch
[root@192 testgit]# 

上記の例では、/ etc / gitconfigファイルがシステムに作成されていない場合、印刷されません。現在のウェアハウスでのgitconfig --listコマンドの結果は、ファイル〜/ .gitconfigと.git / configの合計であることがわかります。より多くの構成情報を知る必要がある場合は、gitconfigコマンドを使用して詳細を確認できます。

2.4記述ファイル

GitWebでプロジェクトの説明情報を表示するために使用されます。デフォルトのコンテンツは次のとおりです。

Unnamed repository; edit this file 'description' to name the repository.

2.5HEADファイル

現在のブランチを指すようにHEADポインタを格納します。つまり、現在アクティブなブランチを記録します。次に例を示します。

[root@localhost testgit]# git status
# 位于分支 master
无文件要提交,干净的工作区
[root@localhost testgit]# cat .git/HEAD 
ref: refs/heads/master
[root@localhost testgit]# git checkout dev-branch
切换到分支 'dev-branch'
[root@localhost testgit]# cat .git/HEAD 
ref: refs/heads/dev-branch
[root@localhost testgit]# 

上記の例では、masterブランチで開始しました。dev-branchブランチに切り替えた後、ファイル.git / HEADの内容はrefs / heads / dev-branchになります。

2.6フックディレクトリ

ディレクトリには多くのフックファイル(一部のスクリプト)が保存されています。これらのファイルは、さまざまなGitコマンドで使用されるカスタムスクリプトであり、操作の前後(commit、rebase、pull)などのGitの特定の段階で自動的に実行できます。git initを実行すると、いくつかのサンプルフックがインストールされますが、デフォルトではすべて無効になっています。有効にする場合は、ファイルの.sampleサフィックスを削除する必要があります。

2.7インデックスファイル

一時記憶域(ステージ)、バイナリファイル。

2.8情報ディレクトリ

リポジトリの他の情報は、このディレクトリに記録されます。

info / exclude:  .gitignoreと同様に、指定されたモードでファイルを無視しますが、.gitignoreは各ディレクトリに固有です。

2.9ログディレクトリ

更新されたすべての参照レコードを保存します。ディレクトリ構造は次のとおりです。

[root@localhost logs]# tree
.
├── HEAD
└── refs
    ├── heads
    │   ├── dev-branch
    │   └── master
    └── remotes
        └── origin
            ├── dev-branch
            └── master

4 directories, 5 files
[root@localhost logs]# 

その中で、HEADはブランチの切り替えを含むすべての変更レコードを記録し、ローカルブランチとリモートブランチの変更レコードをログ/参照に保存します。 

2.10オブジェクトディレクトリ

Gitはコンテンツアドレス可能なファイルシステムです。Gitのコア部分は単純なKey-Valueデータストアです。あらゆるタイプのコンテンツをGitリポジトリに挿入でき、コンテンツをいつでも再度取得できる一意のキーが返されます。

簡単な理解は次のとおりです。オブジェクトディレクトリはGitデータベースです(キーと値のペアのデータベースはmap [key] = valueの形式で想像できます)。コンテンツはキーに従ってアクセスされ、キーは計算された値です。 SHA1による。このディレクトリに格納されるオブジェクトには、(最大で)3つのタイプがあります。データオブジェクト(blobオブジェクト)、ツリーオブジェクト(ツリーオブジェクト)、およびコミットオブジェクト(コミットオブジェクト)です。

(1)情報およびパックディレクトリ

保存されたファイルが非常に大きい場合、gitはそれを圧縮し、info andpackの下に保存します。

(2)2文字コマンドのディレクトリ

まず、これらの2文字は計算されたSHA1値の最初の2文字(合計40文字)であり、残りの38文字はディレクトリ内のファイル名です。

2.11refsディレクトリ

(1)ヘッドディレクトリ

ディレクトリにはローカルブランチ名にちなんで名付けられたファイルが含まれ、SHA1アルゴリズムによって計算された文字列である対応するブランチの最新の送信IDが保存されます。

(2)リモートディレクトリ

ディレクトリにはリモートブランチ名にちなんで名付けられたファイルが含まれ、対応するブランチの最新の送信のID、およびheadsディレクトリの原則保存さます。

(3)タグディレクトリ

開発プロセス中に作成されたタグを保存します。内部のファイルはタグ名で命令され、ファイルの内容は対応するIDです。

3.参考文献

[1]  Gitの記述ファイルとは何ですか?

[2]  gitignore

[3]  gitブランチ

[4]  gitrepository-layout

 

 

 

 

おすすめ

転載: blog.csdn.net/u011074149/article/details/109406589