找出远程服务器上的git版本

rud*_*ter 18 git

我在我的本地机器上寻找git命令,我可以运行以找出在远程服务器上运行的git版本?如果这是可能的话.

Edw*_*son 21

现代git服务器(从git 1.7.12.1开始)将在协议的功能协商中返回其版本信息.虽然没有可以在本地运行的git命令是准确的,但您只需查询git服务器以获取信息,最新版本将提供版本号.

您可以使用Web客户端请求:

<repository url>/info/refs?service=git-upload-pack
Run Code Online (Sandbox Code Playgroud)

并检查agent=报告的第一行.

例如,针对CodePlex:

% curl https://git01.codeplex.com/gittf/info/refs\?service=git-upload-pack
000000bd43569b9f6f29136b6544809eacd2417a308f9341 HEAD\0multi_ack thin-pack
side-band side-band-64k ofs-delta shallow no-progress include-tag multi_ack_detailed
no-done agent=git/1.8.4.msysgit.0
Run Code Online (Sandbox Code Playgroud)

这表明CodePlex正在使用Git for Windows 1.8.4(git/1.8.4.msysgit.0).

或者反对GitHub:

% curl https://github.com/libgit2/libgit2.git/info/refs\?service=git-upload-pack
000000f83f8d005a82b39c504220d65b6a6aa696c3b1a9c4 HEAD\0multi_ack
thin-pack side-band side-band-64k ofs-delta shallow no-progress include-tag
multi_ack_detailed no-done symref=HEAD:refs/heads/master
agent=git/2:2.1.1~peff-bare-reflogs-fetch-616-gc016f98
... ref information removed ...
Run Code Online (Sandbox Code Playgroud)

表明GitHub正在使用自定义git版本: git/2:2.1.1~peff-bare-reflogs-fetch-616-gc016f98.

  • 如何通过身份验证(使用 ssh 远程而不是 https 远程)来做到这一点? (2认同)

小智 5

Edward Thomson建议的方式类似,您还可以使用环境调试变量

GIT_TRACE_PACKET=true git ls-remote --heads https://github.com/libgit2/libgit2.git |& grep agent
12:31:40.317199 pkt-line.c:80           packet:          git< f92d495d44bff2bdb6fd99524a93986ea268c9e8 HEAD\0multi_ack thin-pack side-band side-band-64k ofs-delta shallow deepen-since deepen-not deepen-relative no-progress include-tag multi_ack_detailed no-done symref=HEAD:refs/heads/master agent=git/github-g956b612bf136
Run Code Online (Sandbox Code Playgroud)

再一次,看起来 GitHub 正在使用 Git 的自定义构建:agent=git/github-g956b612bf136.