[英]How do I get the list of SHA values of all the files in a folder of my git repo using JGit library
我相信我可以使用git ls-files -s <file name>
命令通过命令行获取文件夹中所有文件的 SHA 值。 我想知道 JGit Java 库中是否有等效的方法?
PS:我不想自己计算文件的 SHA,文件夹内可能有很多文件,所以我需要获取 git 对象中已经存在的 SHA。 另外,我不能做Runtime.getRuntime().exec("git ls-files -s")
因为主机不会识别git
本身。
要查看索引的 object ID,可以使用在 JGit 中调用的DirCache
。 它允许迭代其条目。
以下示例打印索引中每个文件的 object ID:
DirCache index = repository.lockDirCache();
for (int i = 0; i < index.getEntryCount(); i++) {
DirCacheEntry entry = index.getEntry(i);
System.out.println(entry.getObjectId().getName() + " " + entry.getPathString());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.