我遇到了一个无法正常显示提交的问题。原因并不重要,我只需要检索提交并在更改日志中正确显示它们。
我做了一些研究,我能找到的最好的解决方案是使用jGits RevSort.TOPO使用jGit在拓扑上对RevWalk进行排序。
这是我到目前为止,但它不起作用,提交正在返回之前未分类。其他分拣方法也很好,例如RevSort.REVERSE但TOPO没有任何影响
RevWalk walk = new RevWalk(repo);
ObjectId head = repo.resolve("HEAD");
RevCommit recentCommit = walk.parseCommit(head);
walk.sort(RevSort.TOPO);
walk.sort(RevSort.COMMIT_TIME_DESC, true);
walk.markStart(mostRecentCommit);
List<String> messages = new ArrayList<String>();
for (Iterator<RevCommit> iterator = walk.iterator(); iterator.hasNext();) {
RevCommit commit = iterator.next();
messages.add(commit.getFullMessage());
}
使用git log,它给出了以下内容。提交a867b4a - 添加新功能应该在下一个版本1.12中。
$ git log
commit a867b4af366350be2e7c21b8de9cc6504678a61b`
Author: Me <me@me.com>
Date: Thu Nov 4 18:59:41 2010 -0400
- prepare release version 1.12
commit 25eee4caef46ae64aa08e8ab3f988bc917ee1ce4
Author: Me <me@me.com>
Date: Thu Nov 4 05:13:39 2010 -0400
- More stuff
commit 0766c053c0ea2035e90f504928f8df3c9363b8bd
Author: Me <me@me.com>
Date: Thu Nov 4 00:55:06 2010 -0400
prepare release version **1.11**
commit **a867b4af366350be2e7c21b8de9cc6504678a61b`**
Author: Me <me@me.com>
Date: Thu Nov 4 18:59:41 2010 -0400
- Added new functionality
git log --topo-order works Commit a867b4a - 添加了新功能的正确标签1.12
$ git log --topo-order
commit a867b4af366350be2e7c21b8de9cc6504678a61b`
Author: Me <me@me.com>
Date: Thu Nov 4 18:59:41 2010 -0400
- prepare release version 1.12
commit 25eee4caef46ae64aa08e8ab3f988bc917ee1ce4
Author: Me <me@me.com>
Date: Thu Nov 4 05:13:39 2010 -0400
- More stuff
commit **a867b4af366350be2e7c21b8de9cc6504678a61b`**
Author: Me <me@me.com>
Date: Thu Nov 4 18:59:41 2010 -0400
- Added new functionality
commit 0766c053c0ea2035e90f504928f8df3c9363b8bd
Author: Me <me@me.com>
Date: Thu Nov 4 00:55:06 2010 -0400
prepare release version 1.11