How to find the branch from commit id

此生再无相见时 提交于 2019-12-20 17:27:34

问题


So, I am trying to find branch name in which a given commit was made. (c853d8cf3ae34dae9866b874b96c6529515d7e90)

I have the parent id and commit id referenced on the git issue.
How can I find that given commit id was pushed in 'x' branch?


回答1:


On GitHub specifically, you now can see the branch a given commit is part of.
The blog post "Branch and Tag Labels For Commit Pages" details:

If the commit is not on the default branch, the indicator will show the branches which contain the commit.
If the commit is part of an unmerged pull request, a link will be shown.

Once the commit makes it to the default branch, any tags that contain the commit will be shown, and the default branch will be the only branch listed.


Original answer

You can list those branches:

git branch --contains <commit>

# in your case
git branch --contains <commit> | grep x

More details in "Git: Finding what branch a commit came from".

Don't forget that a commit can be part of several branches.




回答2:


just a cheat.

You can see the branch on the commit detail page of Github like the following:

https://github.com/{github_username}/{repo}/commit/{commit_id}

Ex: https://github.com/chungth/Laravel-5.2-Bootstrap3-starter-site/commit/f81c13234a9da988613e14e52f752abec5f51997

You can see the current branch name on that page



来源:https://stackoverflow.com/questions/15647221/how-to-find-the-branch-from-commit-id

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