could use below code to get "from" branch by commit:
/**
* find out which branch that specified commit come from.
*
* @param commit
* @return branch name.
* @throws GitException
*/
public String getFromBranch(RevCommit commit) throws GitException{
try {
Collection<ReflogEntry> entries = git.reflog().call();
for (ReflogEntry entry:entries){
if (!entry.getOldId().getName().equals(commit.getName())){
continue;
}
CheckoutEntry checkOutEntry = entry.parseCheckout();
if (checkOutEntry != null){
return checkOutEntry.getFromBranch();
}
}
return null;
} catch (Exception e) {
throw new GitException("fail to get ref log.", e);
}
}