《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 git@github.com: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 git@github.com:wangzhizhou2014GitHub/Joker.git时,会在.git/config文件中添加下面内容:

[remote "origin"]
        url = git@github.com: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为空。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值