how do I get all commits of a branch with JGit, without changing the working directory?
Unfortunately the JGit docs are not very good ...
In ruby with grit it is very easy:
repo = Grit::Repo.new(pathToRepo)
repo.commits(branchName, false).each do |commit|
doSomethingWithTheCommit
end
Bye, hurik
I was just looking for a way to list all commits under each branch and I found this thread. I finally did something a bit different from some of the answers I found here and worked.
Thanks for the help
Tried this here first: https://stackoverflow.com/a/13925765/2246865
But it wasn't was working always, so I found this here: http://www.eclipse.org/forums/index.php/t/280339/
Here my solution, it isn't really nice, but it's working ...
You are right, the docs should really be better.
You could use the JGit Log command or use a library like gitective which makes iterating over commits easy. You can look at the source to learn more about JGit.
Other (more complicated) ways are described in this SO-question.
With the code below you can get all commits of a branch or tag:
The varialbe
treeName
will define the tag or branch. ThistreeName
is the complete name of the branch or tag, for examplerefs/heads/master
for the master branch orrefs/tags/v1.0
for a tag called v1.0.Alternatively, you can use the gitective API. The following code does the same as the code above:
Some try/catch will be necessary, I hide them to make the code shorter. Good luck.
A much shorter and clean solution can be done via the "log" command that JGit provides:
See the full snippet at the jgit-cookbook
This seems to work but I thought add(ObjectId branch) to provide a gate to the active branch, but I appear to require a range