有没有办法让 git 通过 http 超时?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6458790/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:36:22  来源:igfitidea点击:

Is there a way to make git over http timeout?

githttptimeoutjenkins

提问by Daniel F. Moisset

I'm having a script running git clone/pull automatically (this is actually happening inside jenkins CI, but my question is more general). The remote git server is HTTPS based. The machine with the git client has a flaky DSL internet connection, so it sometimes reconnects and changes IP address, losing all its existing connections. When the connection fails while the git client is running, the client never succeeds but it doesn't fail with a timeout either, so my script hangs up.

我有一个自动运行 git clone/pull 的脚本(这实际上发生在 jenkins CI 内部,但我的问题更笼统)。远程 git 服务器基于 HTTPS。带有 git 客户端的机器有一个不稳定的 DSL 互联网连接,因此它有时会重新连接并更改 IP 地址,从而丢失所有现有连接。当 git 客户端运行时连接失败,客户端永远不会成功,但它也不会因超时而失败,所以我的脚本挂断了。

I'd like to set up the client so it timeouts after some period (so the script can retry, or log a failure, or take any other action). But I didn't find any timeout option in the git-config manpage. I found a related questionbut it's only for SSH connections. Do you know if there's an alternative for http servers?

我想设置客户端,使其在一段时间后超时(因此脚本可以重试,或记录失败,或采取任何其他操作)。但是我在 git-config 手册页中没有找到任何超时选项。我发现了一个相关的问题,但它仅适用于 SSH 连接。你知道是否有 http 服务器的替代方案?

采纳答案by manojlds

You can try using

您可以尝试使用

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.lowSpeedLimit、http.lowSpeedTime

如果 HTTP 传输速度低于 http.lowSpeedLimit 的时间超过 http.lowSpeedTime 秒,则传输中止。可以被 GIT_HTTP_LOW_SPEED_LIMIT 和 GIT_HTTP_LOW_SPEED_TIME 环境变量覆盖。

回答by Alfred Huang

Additional to CAD bloke's answer:

除了CAD 家伙的回答:

Also

git config --global http.lowSpeedLimit 1000
git config --global http.lowSpeedTime 600

works fine.

工作正常。

The above example means the remote action will block when the speed kept below 1KB/s for 600 seconds(10min), the action will block.

上面的例子表示当速度保持在1KB/s以下600秒(10分钟)时,远程动作将被阻塞,动作将被阻塞。

回答by CAD bloke

Add this to .gitconfig ...

将此添加到 .gitconfig ...

[http]
lowSpeedLimit = 1000
lowSpeedTime = 20

lowSpeedLimit is bytes per second

lowSpeedLimit 是每秒字节数

I call it the Codeplex clause.

我称之为 Codeplex 条款。