Get a list of commits in project

Answered

Hello!
I am developing a plugin for Intellij and therefore wondering is there a functionality in intellij-openapi allowing to get a list of commits in current branch?
It would be perfect if it is possible to get list of com.intellij.openapi.vcs.changes.Change for each commit ever done in project's repository. 
Hope for a quick response, thank you!

0
5 comments
Official comment

Hi,

There are two methods that you may use: `git4idea.history.GitHistoryUtils#history` and `git4idea.history.GitHistoryUtils#loadDetails`. They both execute a `git log` command and allow to provide parameters to it, such as a branch name; they both load commits as `GitCommit` instances each containing commit information and changes to commit parents. The difference is that `history` collects commits to a list (so if commits number is too high can lead to the `OutOfMemoryError`) while `loadDetails` accepts a consumer and allows to process commits one by one.

Thank you for quick and detailed response, Julia!

 

0

Both of these methods need VirtualFile as an argument.
Which real file should it correspond? I don't get it, should I pass each VirtualFile of project, or I should pass project.getProjectFIle() ? 

0

You are supposed to provide a root folder of your git repository. You can use `com.intellij.openapi.vcs.ProjectLevelVcsManager` to find all VCS roots in the project, which VCS they correspond to, roots for specific files, etc.

1

Please sign in to leave a comment.