英文:
git + go - how to handle subprojects with go get
问题
我在我的软件中使用版本控制系统git
。在源代码中,我使用go get
从github自动获取软件。我该如何处理“双git”情况?
当我在目录src/github.com/somename/someproject
上运行git add
时,这会添加任何内容吗?(当我运行git status
时看起来不是这样)
我应该为git get
添加的子目录使用git submodule
吗?
在这种情况下,最佳做法是什么?
编辑:我为我的软件项目设置了自定义的$GOPATH
环境。这就是为什么src/github.com/somename/someproject
目录位于我的软件目录层次结构中的原因。
英文:
I use the version control system git
for my software. And "within" the source code, I use go get
to automatically fetch software from github. How can I handle the "double git" situation?
When I run git add
on the directory src/github.com/somename/someproject
, which is a git repository in itself, will this add anything? (it doesn't look like this when I run git status
)
Should I use git submodule
for the git get
added subdirectories?
What is the best practice in this situation?
Edit: I do have a custom $GOPATH
environment for my software project. This is why the src/github.com/somename/someproject
directory is found inside my software directory hierarchy.
答案1
得分: 3
虽然@nemo的答案可能是正确的方法,但这是我所做的:我从go get
下载的存储库中删除了.git
和.gitignore
文件。我拥有的源路径位于我的源目录内:GOPATH=.../myproject/src/go/
。这样,所有的go get
下载都在我的项目树内,我可以用git来处理它。
我认为这就是"goven"(请参见我在问题上的评论)应该做的事情,但我无法让它工作。
英文:
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. The source path I have is inside my source directory: GOPATH=.../myproject/src/go/
. That way all the go get
downloads are inside my project tree and I can just handle it with 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.
答案2
得分: 2
如果您想要存储您使用的外部包的版本,最好的方式是go import remote语法支持类似github.com/user/project/sub/directory/revision
的形式,但不幸的是它并不支持。关于这个问题,golang-nuts邮件列表上有一个讨论,您可以查看可能的解决方案和注意事项。
最简单的方法可能是fork您使用的项目并导入您的fork,这样您就可以完全控制更新。像github这样的平台使这一过程变得非常容易。
根据go help remote
:
> 新下载的包会被写入GOPATH环境变量中列出的第一个目录(参见'go help gopath')。
因此,您提出的子模块解决方案是可行的,但不太容易使用,因为您必须在获取时指定自定义的GOPATH。我建议您fork该库并引用该fork。
英文:
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. There's a discussion on the golang-nuts mailing list about this very topic, check it out for possible solutions and caveats.
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.
From go help remote
:
> New downloaded packages are written to the first directory
listed in the GOPATH environment variable (see '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. I would recommend forking the library and referencing the fork.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论