我已经在自己的服务器上设置了 git repo,并且可以通过 ssh 处理它,类似的东西(我使用 ssh key )
git clone <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dda8aeb8afb3bcb0b89db0a4aeb8afabb8aff3beb2b0" rel="noreferrer noopener nofollow">[email protected]</a>:/home/git/repo.git
我已经设置了 git 守护进程,所以我可以使用它,如下所示
git clone <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bfcaccdacdd1ded2daffd2c6ccdacdc9dacd91dcd0d2" rel="noreferrer noopener nofollow">[email protected]</a>:/home/git/repo
我已将本地 git 配置为使用 ssh 而不是 https,因此我的 ~/.gitconfig 具有以下内容
[url "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="12676177607c737f77527f6b6177606477603c717d7f" rel="noreferrer noopener nofollow">[email protected]</a>:"]
insteadOf = https://myserver.com
并且以下效果很好
git clone https://myserver.com/home/git/repo
但是当我尝试通过“go get”来处理它时
go get myserver.com/home/git/repo
我收到一个错误
go get: unrecognized import path "myserver.com/home/git/repo": https fetch: Get "https://myserver.com/home/git/repo?go-get=1": dial tcp HERE_IS_IP_ADDR:443: connect: connection refused
我已经尝试过做类似的事情
go env -w GOPRIVATE="myserver.com/home/git/repo"
但它不起作用。
我使用go版本go1.16.4 linux/amd64
有人可以帮忙吗?
最佳答案
当您将存储库指定为要导入的路径时,请尝试将 .git
添加到表示目标存储库根的 block 中:
go get myserver.com/home/git/repo.git
# to get a subpackage:
go get myserver.com/home/git/repo.git/sub/pkg
go help get
有以下段落:
For more about how 'go get' finds source code to download, see 'go help importpath'.
go help importpath
在远程导入路径
部分中解释:
一些托管平台,例如github.com
或bitbucket.org
,会自动处理;对于其他托管解决方案:
To declare the code location, an import path of the form
repository.vcs/path
specifies the given repository, ...
其中.vcs
可以是.git、.hg、.svn、.bzr、.fossil
之一。
关于git - “go get”不适用于我自己的 git 存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69583256/