1

Can someone please share a code snippet that shows how I can pick out commits on only ONE branch using the JGit API.

If I use RevWalk, I get the entire tree, including sub-branches that have been merged into the specified branch.

How can I get JUST the commits on the specified branch without picking up parent commits of branches that may have been merged into the specified branch?

What may also help is to find out what branch a certain commit is sitting on.


Adding some more info:

enter image description here

How can I get all commits along the develop branch? So based on the image above, I need SHAs:

2a34

b468

785c

but NOT:

731a

cbdb

Thanks!

Pankaj Tandon
  • 151
  • 1
  • 6
  • I think, what you are asking for is not possible in Git Which Git command(s) would you use to accomplish this? – Rüdiger Herrmann Oct 24 '16 at 10:53
  • Dont know of any command in the porcelain API. I was wondering if there was a jGit API that could help. How about the second question: How can I find out the branch(es) a certain commit is on? Is there an API for that? – Pankaj Tandon Oct 24 '16 at 13:54
  • Hi, @PankajTandon . Did you manage to solve this? – kolobok Aug 31 '17 at 15:35

1 Answers1

0

In order to traverse the history of a Git repository, starting at a certain branch, you can use the LogCommand as described here: JGit: How to get all commits of a branch? (Without changes to the working directory ...)

The command's addFilter() method can be used to install a RevFilter to exclude certain commits.

Community
  • 1
  • 1
Rüdiger Herrmann
  • 20,512
  • 11
  • 62
  • 79
  • Thanks Rudiger. However, the nameRev command doesn't return the name of the branch. Instead it returns the previous ref with a ~ added at the end. So, for example, if the branch is called develop, the map that is returned by nameRev returns develop~1 on the *second* commit on that branch (The first commit returns 'develop' correctly). This, kind of, puts the kibosh on the approach I was taking, that of finding all commits along a branch. I'm attaching a picture below so that I can make the question clearer. Any ideas? Thanks! – Pankaj Tandon Oct 26 '16 at 03:23