用于 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 07:48:00  来源:igfitidea点击:

git library for Go

gitgo

提问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.

如果你正在寻找一个纯粹用 Go 编写的 git 实现,go-gitfrom source{d}是最成熟和最活跃的选择。

回答by Victor Deryagin

You can just shell out to gitcommand using os/execpackage from Go standard library.

您可以git使用Go 标准库中的os/exec包直接执行命令。

回答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-coredirectory (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 cgofacility. You hence could try wrapping libgit2with it. AFAIK, libgit2is 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 实现