使用JGit列出与给定标记关联的提交 [英] List commits associated with a given tag with JGit

查看:185
本文介绍了使用JGit列出与给定标记关联的提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个历史文件,详细说明所有标签和每个标签的所有提交。

I need to create a history file that details all tags and for each tag, all its commits.

我试图调用存储库对象上的getTags()并使用这些对象ID,但它们不是提交ID。

I've tried to call getTags() on the repository object and use those object id's, but they are not commit id's.

我也尝试使用<$ c存储库中的$ c> getAllRefsByPeeledObjectId()确实带回了提交,但我无法将它们与标签相关联。

I also tried to use getAllRefsByPeeledObjectId() on the repository and that does bring back commits but I can't associate them to tags.

任何想法?

推荐答案

列出所有标签:

List<Ref> call = new Git(repository).tagList().call();
for (Ref ref : call) {
    System.out.println("Tag: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());
}

根据标记列出提交:

我使用基于tag-name的log-command和剥离魔法,如Rüdiger所述:

I'd use the log-command based on the tag-name with the peeled-magic as noted by Rüdiger:

        LogCommand log = new Git(repository).log();

        Ref peeledRef = repository.peel(ref);
        if(peeledRef.getPeeledObjectId() != null) {
            log.add(peeledRef.getPeeledObjectId());
        } else {
            log.add(ref.getObjectId());
        }

        Iterable<RevCommit> logs = log.call();
        for (RevCommit rev : logs) {
            System.out.println("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */);
        }

另请参阅我的 jgit-cookbook 的一些相关例子。

See also my jgit-cookbook for some related examples.

这篇关于使用JGit列出与给定标记关联的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆