<p>Git submodules make for a great what to freeze vendors:</p>
<pre><code> go list -f '{{range $imp := .Imports}}{{printf "%s\n" $imp}}{{end}}' ./... \
| awk -F'[/]' '/[.]/ {printf "%s/%s/%s\n",$1,$2,$3}' \
| sort -u \
| xargs -I REPO -n1 -P1 echo git submodule add -f https://REPO vendor/REPO
</code></pre>
<p><a href="https://github.com/nicerobot/git-freeze" rel="nofollow">git-freeze</a> implements the above.</p>
<p>Note: If you're actually afraid of repo(s) disappearing, fork the repo(s) and import and vendor your fork. Using submodule is still valid and provides a consistent mechanism for vendoring as well as retaining a version trail and update/merge history for both vendor submodules and the parent's integration with updates without cluttering your repo with copies of other packages.</p>
<hr/>**评论:**<br/><br/>dominikh: <pre><p><a href="https://www.reddit.com/r/golang/comments/492w0u/do_you_like_go_get_want_to_vendor_your_code/d0opzll" rel="nofollow">https://www.reddit.com/r/golang/comments/492w0u/do_you_like_go_get_want_to_vendor_your_code/d0opzll</a></p></pre>nicerobot: <pre><p>Sorry, that's wrong. You summed it up in the second paragraph. If you're actually afraid of the repo disappearing, saving all the code into a vendor folder isn't the right approach. It's better to fork the repo and vendor your fork, for which submodule is still valid. The point is, submodules provide a consistent mechanism for vendoring.</p></pre>Fwippy: <pre><p>Awesome, this looks pretty cool. If go authors ever start using semver for their packages, it might be handy to also have a little bit of code that identifies commits that satisfy certain version ranges (i.e. <code>>=1.4</code>)</p></pre>nicerobot: <pre><p>Yea, unfortunately, there's only so far tools can go before significantly benefiting from having language support. Enhancements to the <code>import</code> declaration specification would be a huge win for dependency management. And it can be enhanced without any breaking changes. I wish I had more time to contribute and I'd just enhance it myself.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传