JGit: How to get all commits of a branch? (Without changes to the working directory …)
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: 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 回答1: With the code below you can get all commits of a branch or tag : Repository repository = new FileRepository ( "/path/to/repository/.git" ); String treeName = "refs/heads/master" ; // tag or branch for ( RevCommit commit