《Pro Git 2》學習筆記_Chapter 10_remote & packfiles&refspec

Remote

通常情況下,在.git/refs/下沒有remote夾,它是用來記錄遠程倉庫的分枝信息的,只要遠程倉庫被添加並連接到本地倉庫時,纔會出現。

[root@localhost temp]# tree .git/refs
.git/refs
├── heads
│   └── master
└── tags

2 directories, 1 file


經過與遠程倉庫的同步,remote會出現,並在其下存放遠程分枝的信息:

git remote add origin [email protected]:wangzhizhou2014GitHub/Joker.git

git pull


.git/refs
├── heads
├── remotes
│   └── origin
│       ├── dev
│       └── master
└── tags

4 directories, 2 files

並且這此遠程的分枝信息是隻讀的,HEAD不會指向遠程分枝上,這時是處於HEAD脫離狀態


Packfiles

packfiles可以用來節省存儲空間並使遠程傳送時更加快速,Git會不定期的對.git/objects/下的對象進行壓縮以減少存儲佔用,但你出可以自己手動進行,

方法是運行:git gc命令

使用了上面的命令後,.git/objects/下面的對象會被壓縮成兩個文件,而原來的對象都被壓縮在一個.pack文件中了,.idx文件上記錄着每個文件在.pack文件中的偏移位置以及大小等相關信息:

.git/objects
├── d6
│   └── 70460b4b4aece5915caf5c68d12f560a9fe3e4
├── info
│   └── packs
└── pack
    ├── pack-ae209eaaddfb7080f26609b58d93cdd1f90502d9.idx
    └── pack-ae209eaaddfb7080f26609b58d93cdd1f90502d9.pack


查看.idx文件內容的方法:git verify-pack -v .git/objects/pack/pack-ae209eaaddfb7080f26609b58d93cdd1f90502d9.idx


refspec

我們把遠程倉庫的分枝映射到了本地倉庫的引用目錄下,即.git/refs/remote/origin

當我們輸入:git remote add origin [email protected]:wangzhizhou2014GitHub/Joker.git時,會在.git/config文件中添加下面內容:

[remote "origin"]
        url = [email protected]:wangzhizhou2014GitHub/Joker.git

        fetch = +refs/heads/*:refs/remotes/origin/*

        push=refs/heads/master:refs/heads/master


refspec的格式是:可選的“+”,跟<src>:<dst>,<src>是遠程倉庫中的引用模式,<dst>是本地倉庫的引用模式,"+"表示覆蓋(overwrite)

.git/config 文件中的內容定義了git fetch 各 git push 命令的缺省值。

例如:git push origin :dev 就可以刪除遠程倉庫的master分枝,因爲本地的refspec爲空。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章