如何从ObjectDatabase中检索文件的SHA1

时间:2015-01-22 20:29:22

标签: libgit2sharp

我检查了源代码,但找不到通过其路径从ObjectDatabase检索文件的SHA1的方法。

手动计算SHA1很容易,但需要读取可能导致性能问题的文件。

1 个答案:

答案 0 :(得分:2)

如果您的文件之前已提交过:

Commit commit = repo.Lookup<Commit>(commitSha);

// Or if it's just been committed
// Commit commit = repo.head.Tip;

string shaFromKnownCommit = commit["path/to/file.txt"].Target.Id.Sha;

如果您的文件只是暂存(提升到临时区域):

string shaFromStagedFile = repo.Index["path/to/file.txt"].Id.Sha;
相关问题