简体   繁体   English

去获得分叉回购的工作流程

[英]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: 我可以看到三个问题:

  1. Running 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以进行测试
  2. Changing 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. 此外,即使它确实使用我的文件构建 - 我可以告诉因为它会使它们发现 - 发出的二进制文件根本不起作用。
  3. Changing $GOPATH/src/github.com/ajcrites to /apex and building that way does work, but there are two issues: $GOPATH/src/github.com/ajcrites/apex并构建该方法确实有效,但有两个问题:
    • The file system directory doesn't match the actual repo name which is weird 文件系统目录与实际的repo名称不匹配,这很奇怪
    • I still want to be able to use the actual binary from /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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM