Community
Participate
Working Groups
Consider the following snippet of code. Input: gitRepo, headRevCommit representeting Git repository and head commit respectively. <code> final RevWalk revWalk = new RevWalk(gitRepo); revWalk.sort(RevSort.TOPO); revWalk.markStart(headRevCommit); LinkedList<RevCommit> mainBranchCommits = new LinkedList<>(); RevCommit currentCommit; while ((currentCommit = revWalk.next()) != null) { mainBranchCommits.addFirst(currentCommit); for (int i = 1; i < currentCommit.getParentCount(); ++i) { revWalk.markUninteresting(currentCommit.getParent(i)); } } </code> It's aimed to single out the linear structure from a commit DAG. Bug in case you have the following graph: <code> 1 / \ 2 3 |\ | | \ | | \| | 4 | | 5 </code> the order of traversal is the following: 1, 2, 4, 5. However, the commit 4 shouldn't be there.