ChatGPT解决这个技术问题 Extra ChatGPT

Bower 仅使用 https 安装?

我正在尝试在我们组织数据中心的构建服务器上设置 Bower,但 git 的端口似乎没有在数据中心的防火墙上打开。我可以使用 git 命令行客户端通过 https://[repo] 进行克隆,但不能通过 git://[repo]

是否有一个开关或首选项会指示 bower 使用 https 而不是 git 协议执行 git clone?

我查看了源代码,并考虑更改解析代码以将 git:// 替换为 https://,但我想我会在进行这些长度之前询问。


k
kenorb

您可以让 git 为您替换协议。赶紧跑:

git config --global url."https://".insteadOf git://

使用 HTTPS 协议而不是 Git。


我真的觉得很笨。我一直在尝试 .insteadOf 之前的命令部分,认为@Sindre 告诉我们使用 git 而不是 git。真遗憾这些类似英语的命令。
如果其他人应用此答案,然后想知道如何撤消该全局配置更改(如我),它是:git config --global --unset url."https://".insteadOf
您也可以省略 --global,它会将配置添加到本地 .git/config
在 Windows 机器上,全局配置文件是用户主文件夹下的 .gitconfig,例如 C:\Users[username]。但是,如果 %HOME% 未定义,git 将使用 %HOMEDRIVE% 而来自 bower 的 git 将使用 %USERPROFILE% 代替。而这两个变量可能不同。在我的机器上,一个是 U:,另一个是 C:\Users\myusername。所以无论我尝试什么,凉亭仍然使用 git:// 。我花了一段时间才弄清楚这一点。所以把它写下来,以防有人遇到同样的情况。
@VincentGauthier 在 Windows 中,启动 System Properties -> Advanced -> Environment Variables -> SystemVariables -> New -> 添加一个名为 HOME 的变量并将其值设置为您想要的路径
q
quickshiftin

基于@Sindre 的答案,我在 BASH 中编写了一个小辅助函数,该函数位于我的 ~/.bashrc 文件中。像 grunt 一样调用它,只是现在它被称为 nngrunt。享受!

function nngrunt
{
    # Add a section to the global gitconfig file ~/.gitconfig that tells git to
    # go over http instead of the git protocol, otherwise bower has fits...
    # See http://stackoverflow.com/questions/15669091/bower-install-using-only-https
    git config --global url."https://".insteadOf git://

    # Run grunt w/ any supplied args
    grunt "$@"

    # Now cleanup the section we added to the git config file
    # Of course we have our own extra cleanup to do via sed since the unset command
    # leaves the section around
    # See http://git.661346.n2.nabble.com/git-config-unset-does-not-remove-section-td7569639.html
    git config --global --unset url."https://".insteadOf
    sed -i 's/\[url "https:\/\/"\]//' ~/.gitconfig
    sed -i '/^$/d' ~/.gitconfig
}

M
Mansoor Ul Haq

为我工作git config --global url."git://".insteadOf https://