.Net Git 库,允许在内存中添加/修改文件
有谁知道 C# 的 Git 库允许客户端代码添加&修改内存中的存储库文件?我有一个裸存储库,我想对其进行实用的添加和修改。因为它是一个裸存储库,所以我不想将文件写入文件系统。这样的事情存在吗?
谢谢!
Does anyone know of a Git library for C# that allows client code to add & modify repository files in memory? I have a bare repository that I would like to make additions and modifications to pragmatically. Because it is a bare repository I do not want to write files to the file system. Does something like this exists?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
文件系统上有一个裸存储库。如果您想要一些快速的内存操作,请使用 RAM 磁盘。这样您仍然可以获得 git 的最新功能。
A bare repository IS on the file system. If you would like some fast in-memory manipulation, use a ram disk. This way you still get the up-to-date functionality of git.
GitSharp 公开
Create()
对其Blob
类型进行重载,允许直接写入 Git 对象数据库,而无需工作目录中的中间文件。下面的单元测试(从 BlobTests 稍作修补。 cs)演示了这样的功能:
编辑:
您可能还愿意看一下NGit。它是 JGit 到 .Net 的自动端口。与 GitSharp 相反,它仍然得到维护。
ObjectInserter
(请参阅此处) 看起来像 有希望的东西。注意:如果您愿意使用 Git 作为对象数据库,通过直接编写对象而不使用 Commit 舞蹈,请确保创建一个引用(在
.git/refs
)以防止它们在 git gc 启动时被修剪。注释 2:Git 对象是只读的,因此您无法“修改”
Blob
。但是,如果您创建了指向它的引用,则可以创建一个新的“更新的”Blob,并将引用的目标更改为指向新的“版本”。GitSharp exposes a
Create()
overload on itsBlob
type which allows a direct write to the Git Object database without the need for an intermediate file in a Working Directory.The unit test below (slightly patched from BlobTests.cs) demonstrates such feature:
EDIT:
You might also be willing to take a look at NGit. It's an automated port of JGit to .Net. Contrarily to GitSharp, it is still maintained.
The
ObjectInserter
(see here) looks like something promising.Note: If you're willing to use Git as an object database, by directly writing objects without the Commit dance, make sure to create a reference (in
.git/refs
) to prevent them from being pruned upon agit gc
launch.Note 2: Git objects are read only, so you won't be able to "modify" a
Blob
. However, if you created a reference pointing at it, you can create a new "updated"Blob
, and change the target of the reference to point at the new "version".