JGit retrieve branch on which a commitID was made

岁酱吖の 提交于 2020-01-05 04:37:12

问题


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.


回答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.



来源:https://stackoverflow.com/questions/9039558/jgit-retrieve-branch-on-which-a-commitid-was-made

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!