如何从对象数据库中检索文件的 SHA1



我已经检查了源代码,但找不到通过路径从对象数据库中检索文件的 SHA1 的方法。

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

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

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;

最新更新