英文:
'go get' doesn't work with my own git repository
问题
我在自己的服务器上设置了git仓库,并通过ssh进行操作,类似这样(我使用ssh密钥):
git clone username@myserver.com:/home/git/repo.git
我还设置了git守护进程,所以我可以这样使用:
git clone username@myserver.com:/home/git/repo
我已经配置了本地git使用ssh而不是https,所以我的~/.gitconfig文件如下:
insteadOf = https://myserver.com
并且以下命令可以正常工作:
git clone https://myserver.com/home/git/repo
但是当我尝试使用"go get"命令处理它时,出现了错误:
go get: 无法识别的导入路径"myserver.com/home/git/repo": https获取:获取"https://myserver.com/home/git/repo?go-get=1"时出错:拨号tcp HERE_IS_IP_ADDR:443: 连接被拒绝
我已经尝试过类似以下的操作,但没有成功:
go env -w GOPRIVATE="myserver.com/home/git/repo"
我使用的是go版本go1.16.4 linux/amd64
有人可以帮忙解决吗?
英文:
I have set up git repo on my own server and can deal with it via ssh, something like that (I use ssh key for it)
git clone username@myserver.com:/home/git/repo.git
and I have set up git daemon, so I can use it something like following
git clone username@myserver.com:/home/git/repo
I have configured local git to use ssh instead of https, so my ~/.gitconfig has following
insteadOf = https://myserver.com
and following works well
git clone https://myserver.com/home/git/repo
but when I try to deal with it by 'go get'
go get myserver.com/home/git/repo
I got an error
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
I have already tried to do something like that
go env -w GOPRIVATE="myserver.com/home/git/repo"
but it doesn't work.
I use go version go1.16.4 linux/amd64
Could somebody help with it?
答案1
得分: 2
当您将您的存储库指定为Go的导入路径时,请尝试在表示目标存储库根目录的部分中添加.git
:
go get myserver.com/home/git/repo.git
# 获取子包:
go get myserver.com/home/git/repo.git/sub/pkg
go help get
中有以下段落:
> 要了解有关如何下载源代码的更多信息,请参阅go help importpath
。
go help importpath
在远程导入路径
部分解释了以下内容:
一些托管平台,如github.com
或bitbucket.org
,会自动处理;对于其他托管解决方案:
> 要声明代码位置,形式为
>
> repository.vcs/path
>
> 指定给定的存储库,...
其中.vcs
可以是.git, .hg, .svn, .bzr, .fossil
之一。
英文:
When you designate your repo as an import path to go, try adding .git
to the chunk that represents the root of the target repository :
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
has the following paragraph :
> For more about how 'go get' finds source code to
download, see 'go help importpath'.
go help importpath
explains, in the Remote import paths
section :
a few hosting platforms, like github.com
or bitbucket.org
, are automatically handled ; for other hosting solutions :
> To declare the code location, an import path of the form
>
> repository.vcs/path
>
> specifies the given repository, ...
where .vcs
can be one of .git, .hg, .svn, .bzr, .fossil
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论