[英]Go get workflow for forked repo
I am using apex
and have installed it with go get github.com/apex/apex/cmd/apex
. 我正在使用
apex
并安装了go get github.com/apex/apex/cmd/apex
。 I have $GOPATH/bin/apex
which works great. 我有
$GOPATH/bin/apex
,效果很好。 I wanted to make some contributions to apex, so I forked it and ran go get github.com/ajcrites/apex/cmd/apex
. 我想为apex做一些贡献,所以我把它分叉并运行
go get github.com/ajcrites/apex/cmd/apex
。 So far so good. 到现在为止还挺好。
The problem comes when I want to actually test my local changes to the project. 当我想实际测试我对项目的本地更改时,问题就来了。 There are three issues I can see:
我可以看到三个问题:
go build
locally doesn't work because the main.go
file imports directly from $GOPATH/src/github.com/apex
. go build
不起作用,因为main.go
文件直接从$GOPATH/src/github.com/apex
。 I need it to import from $GOPATH/src/github.com/ajcrites
for the purposes of testing $GOPATH/src/github.com/ajcrites
以进行测试 main.go
manually to import from ajcrites
is wonky since I can't/shouldn't commit these changes. main.go
以从ajcrites
导入是ajcrites
,因为我不能/不应该提交这些更改。 Moreover even though it does build with my files -- I can tell because it lints them -- the binary that is emitted doesn't work at all. $GOPATH/src/github.com/ajcrites
to /apex
and building that way does work, but there are two issues: $GOPATH/src/github.com/ajcrites
为/apex
并构建该方法确实有效,但有两个问题:
/apex
without clobbering it just for the purposes of testing local changes /apex
的实际二进制文件,而不是为了测试本地更改而破坏它 Is there a recommended way to clone forked go
repositories and build/test locally? 是否有克隆分叉推荐的方式
go
仓库和构建/测试本地?
If you don't want to change the import paths in your code, or vendor the source in your project, don't change directory where the code lies in GOPATH. 如果您不想更改代码中的导入路径,或者在项目中提供源代码,请不要更改代码位于GOPATH中的目录。 If you want to change the import path, you will need to rewrite that in all the source, or you end up importing multiple versions of the package.
如果要更改导入路径,则需要在所有源中重写该路径,或者最终导入包的多个版本。
Go into the $GOPATH/src/github.com/apex/apex
directory and change the origin
remote to your forked repo. 进入
$GOPATH/src/github.com/apex/apex
目录并将origin
远程更改为分叉仓库。 By convention, I also add the original repo as an upstream
remote, so I can conveniently fetch and merge changes from there as well. 按照惯例,我还将原始repo添加为
upstream
远程,因此我也可以方便地从那里获取和合并更改。
Since vendoring is enabled by default since go1.6, you can put the source in a vendor/
directory under your control, and make your modifications there. 由于自从go1.6以来默认启用了vendoring,因此您可以将源放在您控制的
vendor/
目录中,并在那里进行修改。 Using git submodules can also allow you to keep it under separate version control, but linked to your project. 使用git子模块还可以让您将其保持在单独的版本控制下,但链接到您的项目。
Here's the flow I recommend and use for managing the Gorilla organization on GitHub: 以下是我推荐并用于在GitHub上管理Gorilla组织的流程:
$ go get github.com/gorilla/csrf
$ cd $GOPATH/src/github.com/gorilla/csrf
# Alternatively, you can git remote remove origin + re-add as SSH
$ git remote add elithrar git@github.com:elithrar/csrf.git
$ git checkout -b new-feature-X
$ <do some work on it>
# Install those changes.
$ go install ./...
That's it. 而已。 No need to change import paths in any existing programs.
无需在任何现有程序中更改导入路径。 If you're vendoring the dependencies, you can just change it in the vendored copy.
如果您要销售依赖项,则可以在销售副本中进行更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.