在此 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,还可以创建 Blob
或 Trees
。可以在 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/