c# - 提交到 Git 对象数据库有什么好处?

标签 c# .net git libgit2sharp

在此 libgit2sharp issue 中的评论讨论中突出显示我可以针对对象数据库创建提交?

什么提交到对象数据库?

为什么比普通的 git add 和 git commit 更有优势?

我正在尝试将提交历史从另一个源代码控制系统 SourceGear 导入到 Git 中。目前我的逻辑只是循环遍历其他源代码控制系统中的文件,获取特定版本及其提交信息并执行 repo.Index.Stage 然后 repo.Commit。我假设这是正确的,我应该使用对象数据库吗?

最佳答案

当使用 LibGit2Sharp 时,标准的提交方式确实是以下工作流程:

using (var repo = new Repository("path/to/a/repository"))
{
    // do stuff

    repo.Index.Stage("path/to/file1");
    repo.Index.Stage("path/to/file2");

    repo.Commit("This is my commit", ....);

    // more stuff
}

但是,这需要一个非裸存储库:一个包含工作目录索引 的存储库。

Stage() 调用将工作目录中的文件注册到 index 中。 Commit() 调用会在对象数据库 中创建索引 内容的不可变时间戳快照。

从 v0.9 版本开始,LibGit2Sharp 允许直接创建提交到对象数据库,而不需要 Stage() 任何东西。事实上,这甚至适用于裸存储库。

除了提交之外,使用新的 ObjectDatabase API,还可以创建 BlobTrees。可以在 ObjectDatabaseFixture 中找到一些可能使用的示例 单元测试。

What is committing to the obect database?

事实上,提交总是最终被存储到对象数据库中。新的 API 公开了一些较低级别的操作,这些操作可能会在某些高级脚本操作中派上用场。

Why is advantageous over doing a normal git add and git commit?

哇...这是一个广泛的子问题。并且没有有限的答案列表 ;-) 以下是一些可能的答案:

  • 这允许您独立于任何提交直接创建 Blob 和/或树
  • 使用标准的 working directory -> index -> odb 工作流程,一次只能准备一个提交。使用此 API,您可以在非顺序流中创建 Blob 和树,然后在最近的时刻决定将哪个树关联到提交。
  • 此 API 还允许明确选择要创建的 Commit 应承担的父项
  • Git 是一个内容可寻址的文件系统,一个不可变的、只能追加的对象数据库。此 API 促进了标准源代码控制之外的其他类型的使用。

At the moment my logic simply loops over the files in the other source control system, gets a certain version and its commit info and does a repo.Index.Stage and then repo.Commit. I'm assuming that is correct, should I use the object database?

考虑到您的用例,看起来标准工作流程就足够了。

关于c# - 提交到 Git 对象数据库有什么好处?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10734925/

相关文章:

c# - 比较两个 .net 对象值的 'similarity'

c# - 无法在 .NET Core 3.0 中获得基于 JWT 的安全性

c# - 为什么我调用 Twitter 用户时间线返回 "401 Unauthorized."?

c# - LINQ to SQL 不会生成 sargable 查询

git - 是否有 Git Server Side Hook 可以为存储库大小设置配额?

c# - 如何在不拆分单词的情况下将字符串拆分为List <string>?

c# - 有没有办法检查代码是否在 TransactionScope 中执行?

c# - PE32+和PE32有什么区别?

java - Eclipse 不显示 git repo 中的所有包

linux - gnutls_handshake() 失败 : Handshake failed GIT