[英]How do I get the list of SHA values of all the files in a folder of my git repo using JGit library
I believe that I can get the SHA values of all the files in a folder through command line by using git ls-files -s <file name>
command.我相信我可以使用
git ls-files -s <file name>
命令通过命令行获取文件夹中所有文件的 SHA 值。 I want to know if there is an equivalent way in JGit Java library?我想知道 JGit Java 库中是否有等效的方法?
PS: I don't want to calculate SHA of files myself and there can be many files inside the folder so I need to get SHAs which are already present in git objects. PS:我不想自己计算文件的 SHA,文件夹内可能有很多文件,所以我需要获取 git 对象中已经存在的 SHA。 Also, I can't do
Runtime.getRuntime().exec("git ls-files -s")
as the host machine will not identify git
itself.另外,我不能做
Runtime.getRuntime().exec("git ls-files -s")
因为主机不会识别git
本身。
To see the object IDs of the index, you can use the DirCache
as it is called in JGit.要查看索引的 object ID,可以使用在 JGit 中调用的
DirCache
。 It allows to iterate over its entries.它允许迭代其条目。
The following example prints the object ID of each file in the index:以下示例打印索引中每个文件的 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.