Sometimes people don't need advice, they just need someone to listen and care.
Toggle navigation
Home
Archives
Tags
About
如何Fork Go packages
Golang
2018-05-16 03:56:24
234
0
0
william
Golang
 Go使得使用软件包变得非常简单,所有你需要做的就是...... ```bash $ go get github.com/org/magic ``` 但是当你发现一个bug或想要扩展包时,你会做什么?通常在Github上fork,做一些修改,向上游提交一个PR ,然后使用你的分支项目,直到你的代码被合并到upstream/master。使用Go软件包有点困难,因为你不能这么做 ```bash $ go get github.com/fork/magic ``` 这是不正确的,因为如果你派生一个具有引用自身的import语句的仓库,它们将在fork中被破坏。 ## 你可以使用的解决方案之一是设置一个不同的远程并拉代码 ```bash $ go get github.com/org/magic $ cd GOPATH/src/github.com/org/magic $ git remote -v origin https://github.com/org/magic.git(fetch) origin https//github.com/org/magic(推送) ``` 然后您可以设置您的远程分支并提取您的代码... ```bash $ git remote add fork https://github.com/fork/magic.git $ git pull fork master ``` 这将允许您使用您的应用程序测试和运行您的代码。这很容易,但它带有一些维护问题,可能会在未来轻松地破坏您的应用程序。例如,如果你运行 ``` bash $ go get -u github.com/org/magic ``` 它会将你的软件包更新回**master**分支,并且你的改变将会消失,如果你没有 **vendor** 包并且想要在**Dockerfile**中使用你的软件包,你将需要在那里写一些东西来使用你的分支软件包。 ## 还有一种解决方案是使用Glide:vendor包管理Golang。 首先,您需要安装glide,然后**glide init**可以使用命令设置新项目,**glide update**使用扫描和规则重新生成依赖项版本,然后**glide install**安装**glide.lock**文件中列出的版本,跳过扫描,除非**glide.lock**未找到该文件将执行更新。 但是,glide如何帮我解决fork问题?在glide.yaml配置中。 ``` yaml package: github.com/sasso/my-project import: - package: github.com/org/magic repo: https://github.com/fork/magic.git ``` 通过添加**repo**glide将始终从您的**fork**拉代码,并允许任何生成系统总是使用**fork**包。当您的代码更改被upstream/master 接受时,您现在唯一需要执行的操作是删除**repo**并**glide update**再次运行。 这只是**glide**所能提供的功能之一,需要了解更详细的信息可以参考[glide文档](https://glide.readthedocs.io/en/latest/glide.yaml/)。 还请记住,随着代码更改,请始终向**upstream/master**提交PR 。它将以同样的方式使您的社区受益! 
Pre:
使用Statefulset在Kubernetes集群中部署Etcd集群
Next:
Intellij IDEA神器居然还有这些小技巧
0
likes
234
Weibo
Wechat
Tencent Weibo
QQ Zone
RenRen
Please enable JavaScript to view the
comments powered by Disqus.
comments powered by
Disqus
Table of content