1

When I checkout from a commitID, git goes into a NO_BRANCH detached state. So the JGit APi which I use to get the branch name is returning the commit. So I need to a way, in JGit API, to find the branch on which this commit was made.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Kamal
  • 325
  • 1
  • 3
  • 9

1 Answers1

1

Using the detached-branch mode (i.e. checking out from a commit) is really not recommended: http://sitaramc.github.com/concepts/detached-head.html

First of all, I do not know how you get the commit SHA. Usually you find a commit by scanning a branch (using log for example). So the question you should ask yourself is how you get the commit ID and you will find the branch from this data.

For your specific problem, I suppose there is a way to find the branch name based on the RevCommit object. However, you should know it is not natural at all.

If you follow the link above, you will understand how Git is constructed and why your goal is to get a commit from other data, and not the other way around.

Vince
  • 164
  • 2