用于 Go 的 git 库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13532389/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git library for Go
提问by vhdirk
As a pet project, I want to develop a note taking app using git as storage backend. (I suspect this doesn't exist yet, given this guy's blog post: http://jarofgreen.co.uk/2012/08/how-about-a-mobile-note-app-backed-by-git/)
作为一个宠物项目,我想开发一个使用git作为存储后端的笔记应用程序。(鉴于此人的博客文章,我怀疑这还不存在:http: //jarofgreen.co.uk/2012/08/how-about-a-mobile-note-app-backed-by-git/)
Now, I'd like to take this as an opportunity to play around with Go a bit. However, I cannot seem to find any (not even the tiniest approach to) git library for Go. Is there actually any?
现在,我想借此机会稍微玩一下围棋。但是,我似乎找不到任何(甚至不是最微小的方法)用于 Go 的 git 库。真的有吗?
Obviously my knowledge of Go is non-existant, so writing bindings for libgit doesn't seem a fun way to start... (and I would probably resort to ruby, which I don't know either)
显然我对 Go 的了解并不存在,所以为 libgit 编写绑定似乎不是一个有趣的开始方式......(我可能会求助于 ruby,我也不知道)
回答by Fernando á.
I'd say git2gois the git bindings library to use in Go. It is updated regularly and maintained by the people running libgit2.
我会说git2go是在 Go 中使用的 git 绑定库。它由运行 libgit2 的人员定期更新和维护。
If you are looking for a git implementation purely written in Go, go-gitfrom source{d}is the most mature and active option.
回答by Victor Deryagin
回答by mcuadros
Since a few years ago, my team and I, we were coding a pure git implementation in Go, it avoids to have any c/c++ dependency and make it more flexible and easy to extend.
几年前,我和我的团队在 Go 中编写了一个纯 git 实现,它避免了任何 c/c++ 依赖并使其更加灵活和易于扩展。
https://github.com/src-d/go-git
https://github.com/src-d/go-git
go-git aims to reach the completeness of libgit2 or jgit, nowadays covers the majority of the plumbing read operations and some of the main write operations, but lacks the main porcelain operations such as merges.
go-git 的目标是达到 libgit2 或 jgit 的完整性,现在涵盖了大部分管道读操作和一些主要写操作,但缺少合并等主要瓷器操作。
回答by kostix
What Victor proposed is indeed the "official" way to "script" Git as envisioned by its developers. Git's commands are divided in the two broad groups specifically for this purpose: the "plumbing" commands are low-level and inteneded mostly to be used by other programs; the "porcelain" command are intended to interact with the user, and call plumbing commands to do their work. Look inside the /usr/lib/git-core
directory (might be different on your system) to get the idea of how many plumbing commands Git has.
Victor 提出的确实是其开发人员所设想的“编写”Git 的“官方”方式。为此,Git 的命令分为两大类:“管道”命令是低级的,主要用于其他程序;“瓷器”命令旨在与用户交互,并调用管道命令来完成他们的工作。查看/usr/lib/git-core
目录内部(可能在您的系统上有所不同)以了解 Git 有多少管道命令。
On the other hand, Go supports linking with shared libraries via its cgo
facility. You hence could try wrapping libgit2
with it. AFAIK, libgit2
is not yet fully on par with the Git itself, but it is able to read/write Git repositories, do branching etc — supposedly it will be enough for your task.
另一方面,Go 支持通过其cgo
工具链接共享库。因此,您可以尝试libgit2
用它包装。AFAIKlibgit2
还不能完全与 Git 本身相提并论,但它能够读/写 Git 存储库、进行分支等——据说这足以完成你的任务。
Okay, after I wrote all that, I scrolled down the "Bindings" entry on the libgit2
's site and found go-git
...
好的,在我写完所有这些之后,我向下滚动了网站上的“绑定”条目libgit2
,发现go-git
......
回答by Thomas Kappler
A search for "git" on GoDocturns up some projects. There's a libgit2 wrapper, and at the bottom is an unfinished Git implementation in Go.
一对GoDoc的“混帐”的搜索变成了一些项目。有一个 libgit2 包装器,底部是Go 中未完成的 Git 实现。