5

如何设置git push和git pull的超时时间?

 3 years ago
source link: https://www.lujun9972.win/blog/2020/06/03/%E5%A6%82%E4%BD%95%E8%AE%BE%E7%BD%AEgit-push%E5%92%8Cgit-pull%E7%9A%84%E8%B6%85%E6%97%B6%E6%97%B6%E9%97%B4%EF%BC%9F/index.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

如何设置git push和git pull的超时时间?

不知道为什么,最近从 github 上git push 和 git pull 的时候总是不太稳定,有时候 pull 了半天都拉不下来,然后中断后重试一次又很顺畅了。

所以我想主动设置git push 和 git pull 的超时时间,这样我可以在脚本中监测退出状态后自动进行重试,而不是死等。

目前来看,似乎 git 并没有一个配置项是能保证超过一段时间后一定终止退出的,只能通过 timeout 命令才能保证超时退出。

然而很多 UNIX 系统没有 timeout 命令怎么办呢?我目前只找到两个近似的解决方案,希望各位大神能提供其他的解决方法。

首先,通过 man git-config 我们可以发现 http.lowSpeedLimithttp.lowSpeedTime 这两个选项是近似满足要求的:

http.lowSpeedLimit, http.lowSpeedTime
    If the HTTP transfer speed is less than http.lowSpeedLimit for
    longer than http.lowSpeedTime seconds, the transfer is aborted. Can
    be overridden by the GIT_HTTP_LOW_SPEED_LIMIT and
    GIT_HTTP_LOW_SPEED_TIME environment variables.

然而这两个选项只针对 HTTP 协议生效,其他协议则需要另辟蹊径。

另一方面,既然 git 的低层是使用 ssh 协议,那么其实我们可以通过通过配置 ssh_configConnectTimeout 来设置连接服务器的超时时间。 但这个选项只针对连接服务器这个阶段生效(即创建连接,SSH 握手和密钥交换这三个阶段),之后就无法进行超时约束了。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK