Git的传输协议如何工作 [英] How does Git's transfer protocol work
问题描述
我在Git上工作了一年多,现在我必须向团队中的其他人解释它.这就是为什么我需要更多背景知识的原因. 去年,我花了大部分时间阅读Git书,最近我又继续阅读第10章.在
I am working with Git for more than one year and now I have to explain it to others in our group. That is why I need a bit more backround. I went thourgh most of the Git Book in the last year and recently I continued with chapter 10. In chapter 10.6 I got completely stuck:
让我们遵循simplegit库的http-fetch过程:
Let’s follow the http-fetch process for the simplegit library:
$ git clone http://server/simplegit-progit.git
此命令要做的第一件事是下拉info/refs文件. 此文件由update-server-info命令编写,因此 您需要将其启用为接收后挂钩,以进行HTTP 运输以正常工作:
The first thing this command does is pull down the info/refs file. This file is written by the update-server-info command, which is why you need to enable that as a post-receive hook in order for the HTTP transport to work properly:
=> GET info/refs
ca82a6dff817ec66f44342007202690a93763949 refs/heads/master
我有一个小型测试仓库https://github.com/to_my/repo
,git clone
效果很好.但是
I have a small test repo https://github.com/to_my/repo
and git clone
works well. But
- 文件夹
info/refs
在哪里?我只在clone
... 之后找到一个 - 我应该如何使用
update-server-info
命令?是git clone的一部分吗? - 尽管我了解钩子(我认为)并使用预提交钩子来自动增加软件包版本,但我对"...这就是为什么您需要将其启用为接收后钩子"感到迷惑. /li>
- 我在git bash工作中无法获得命令
GET info/refs
.
/.git/info/exclude
- Where is the folder
info/refs
? I only find a/.git/info/exclude
afther theclone
... - How should I use the
update-server-info
command? Is it part of git clone somehow? - I am competely lost with "...which is why you need to enable that as a post-receive hook" although I understand hooks (I thought) and use a pre-commit hook for automatically increasing the package version.
- I can't get the command
GET info/refs
in git bash work.
很抱歉,如果问题很愚蠢,但我只是不明白如何将文档中的这些内容放在一起.
Sorry if the questions are stupid, but I just don't understand how to put these pieces from the documentation together.
推荐答案
文件夹信息/引用在哪里?我只找到/.git/info/排除此克隆...
Where is the folder info/refs? I only find a /.git/info/exclude afther the clone...
没有这样的文件夹(它不是目录),但是-.git/info/refs
-将是 file 所在的位置(如果有文件的话)
There is no such folder (it's not a directory), but that—.git/info/refs
—would be where the file would be, if there were a file there.
我应该如何使用update-server-info命令?它是git clone的一部分吗?
How should I use the update-server-info command? Is it part of git clone somehow?
通常,您应该不使用它:它仅用于哑"传输. 智能"(双向对话)传输不需要它.
In general, you should not use it: it's only for "dumb" transports. "Smart" (two way conversation) transports don't need it.
尽管我了解钩子(我认为)并使用预提交钩子来自动增加软件包版本,但我对"...这就是为什么需要将其启用为接收后钩子"感到迷惑. /p>
I am competely lost with "...which is why you need to enable that as a post-receive hook" although I understand hooks (I thought) and use a pre-commit hook for automatically increasing the package version.
如果出于某种原因要启用哑传输,则每次文件需要创建或更新时,都需要运行某些文件来创建或更新多个文件.每当引用更改时,都需要更新info/refs
文件,因此在接收后挂钩中可以很好地运行"something". 东西"是命令git update-server-info
.
If, for some reason, you want to enable dumb transports, you need to run something to create or update several files every time they need creating or updating. The info/refs
file needs to be updated whenever references change, so a good place to run the "something" is in a post-receive hook. The "something" is the command git update-server-info
.
请注意,如果您未在服务器上运行仅推送的裸存储库,则仅运行后接收脚本git update-server-info
是不够的,因为可以通过其他方式添加提交和其他对象(手动git commit
例如).在这种情况下,您可能会使用例如cron作业,以时钟驱动为基础来创建或更新哑传输信息.
Note that if you are not running a push-only bare repository on a server, having a post-receive script run git update-server-info
is not sufficient, since commits and other objects can be added by other means (manual git commit
s for instance). In this case you might use, e.g., a cron job to create-or-update dumb-transport information on a clock-driven basis.
我无法在git bash工作中获得命令
GET info/refs
.
如果该文件存在,则可以通过HTTP获得该文件,例如,从浏览器或使用curl
命令.
If the file existed, you would obtain it via HTTP, e.g., from a browser or with the curl
command.
这篇关于Git的传输协议如何工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!