[英]git + go - how to handle subprojects with go get
I use the version control system git
for my software. 我为我的软件使用版本控制系统
git
。 And "within" the source code, I use go get
to automatically fetch software from github. 在“源代码”中,我使用
go get
来自动从github获取软件。 How can I handle the "double git" situation? 我该如何处理“双git”情况?
When I run git add
on the directory src/github.com/somename/someproject
, which is a git repository in itself, will this add anything? 当我在目录
src/github.com/somename/someproject
上运行git add
时,这本身就是一个git存储库,这会添加什么吗? (it doesn't look like this when I run git status
) (当我运行
git status
时,它看起来不像这样)
Should I use git submodule
for the git get
added subdirectories? 我应该使用
git submodule
为git get
添加子目录吗?
What is the best practice in this situation? 在这种情况下,最佳做法是什么?
Edit: I do have a custom $GOPATH
environment for my software project. 编辑:我的软件项目有一个自定义的
$GOPATH
环境。 This is why the src/github.com/somename/someproject
directory is found inside my software directory hierarchy. 这就是我的软件目录层次结构中找到
src/github.com/somename/someproject
目录的原因。
While @nemo's answer is probably the way to go, this is what I did: I stripped the .git
and .gitignore
files from the go get
downloaded repositories. 虽然@ nemo的答案可能是要走的路,但这就是我所做的:我从
go get
下载的存储库中删除了.git
和.gitignore
文件。 The source path I have is inside my source directory: GOPATH=.../myproject/src/go/
. 我的源路径在我的源目录中:
GOPATH=.../myproject/src/go/
。 That way all the go get
downloads are inside my project tree and I can just handle it with git. 这样所有
go get
下载都在我的项目树中,我可以用git处理它。
I think that this is what "goven" (see my comment on my question) is supposed to do, but I wasn't able to get it to work. 我认为这就是“goven”(参见我对我的问题的评论)应该做的,但我无法让它发挥作用。
If you want to store the revision of the foreign packages you use, it would be best if the go import remote syntax would support something like github.com/user/project/sub/directory/revision
, which it doesn't unfortunately. 如果你想存储你使用的
github.com/user/project/sub/directory/revision
的修订版,最好是go import远程语法支持像github.com/user/project/sub/directory/revision
这样的东西,不幸的是它。 There's a discussion on the golang-nuts mailing list about this very topic, check it out for possible solutions and caveats. 关于这个话题的golang-nuts邮件列表有一个讨论 ,请查看可能的解决方案和警告。
The simplest way to do this, is probably to fork the projects you use and import your forks, so you have full control over updates. 最简单的方法是分叉您使用的项目并导入您的分支,这样您就可以完全控制更新。 Platforms like github make it really easy to do so.
像github这样的平台让它变得非常容易。
From go help remote
: 从
go help remote
:
New downloaded packages are written to the first directory listed in the GOPATH environment variable (see 'go help gopath').
新下载的包将写入GOPATH环境变量中列出的第一个目录(请参阅“go help gopath”)。
So your proposed submodule solution is possible but is not as easy to use, as you have to specify a custom GOPATH while fetching. 因此,您提出的子模块解决方案是可行的,但不是那么容易使用,因为您必须在获取时指定自定义GOPATH。 I would recommend forking the library and referencing the fork.
我建议分叉库并引用fork。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.