我正在尝试使用gerrit中托管的一个项目作为golang中的依赖项。
- 我在gerrit中安装了go导入插件
- 我在.gitconfig中添加了以下内容:
[url "ssh://myuser@gerrit.example.com:29418"]
insteadOf = https://gerrit.example.com
现在我运行:
go get gerrit.example.com/myproject
但它失败了:
go get: module gerrit.example.com/myproject: git ls-remote -q origin in /home/me/go/pkg/mod/cache/vcs/513f491cb527a8cec5b684e8d77254c851f76499e1f725440f98d4e9ad8bbf4f: exit status 128:
fatal: project a/myproject not found
fatal: Could not read from remote repository.
确保全局git配置没有按照以下方式设置:
git config --global url."git@gerrit.example.com:".insteadOf "https://gerrit.example.com"
.gitconfig
[url "git@gerrit.example.com"]
insteadOf = https://gerrit.example.com
对于git工具的常规使用,设置一个~/.ssh/config
文件是很方便的。为此,请运行以下命令:
mkdir ~/.ssh
chmod 700 ~/.ssh
touch ~/.ssh/config
chmod 600 ~/.ssh/config
请注意,上面文件和目录的权限对于SSH在大多数Linux系统上的默认配置中工作是必不可少的。
然后,编辑~/.ssh/config
文件以匹配以下内容:
Host gerrit.example.com
HostName gerrit.example.com
Port 29418
User USERNAME_HERE
IdentityFile ~/.ssh/id_gerrit_example_com
请注意以上文件中的间距很重要,如果不正确,文件将无效。
其中USERNAME_HERE
是您的gerrit
用户名,~/.ssh/id_rsa
是文件系统中SSH私钥的路径。您已经将其公钥上载到gerrit
。
注意:我创建此配置只是假设,因为我没有要测试的gerrit
设置。