Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell which branch a github commit was for?

Tags:

git

github

On github, when I view a commit, it shows me the commit message and the changes, along with any comments at the bottom. However, it doesn't tell me what branch the commit was checked in to. Even if I 'Browse Code', it is browsing the code for a particular 'tree' (presumably the state of the code when the commit was made), rather than for a particular branch.

I know that commits in git aren't intrinsically linked to a branch, but surely they are always going to be first committed into a particular branch? Isn't the commit tagged with that branch, and can I view which branch it was somehow?

like image 724
Jez Avatar asked Feb 20 '12 12:02

Jez


People also ask

How do you find the branch a commit was for GitHub?

UPDATE: 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.

How do you tell which branch a commit is from?

You could do this: git log --merges <commit>.. to see merge commits that have the given commit as an ancestor. (If the commit was only merged once, the first one should be the merge you're after; otherwise you'll have to examine a few, I suppose.)

Can you see commit history in GitHub?

On GitHub, you can see the commit history of a repository by: Navigating directly to the commits page of a repository. Clicking on a file, then clicking History, to get to the commit history for a specific file.


3 Answers

OK, the answer to this question, fundamentally, is: there is no definitive way to tell. Mercurial actually tags commits with the name of the branch they were checked in to, but git simply doesn't; apparently, it isn't considered important what the name of the branch was. This was a design decision and it doesn't look like it's going to change.

like image 85
Jez Avatar answered Sep 24 '22 19:09

Jez


If you know the commit number, you can simply do this

git branch --contains <commit>

This should give you the branch name in which the commit was made.

UPDATE: 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.

enter image description here

like image 24
PriyankaK Avatar answered Sep 24 '22 19:09

PriyankaK


From git help branch:

With --contains, shows only the branches that contain the named commit (in other words, the branches whose tip commits are descendants of the named commit).

With --merged, only branches merged into the named commit (i.e. the branches whose tip commits are reachable from the named commit) will be listed.

With --no-merged only branches not merged into the named commit will be listed. If the argument is missing it defaults to HEAD (i.e. the tip of the current branch).

like image 23
RobinGower Avatar answered Sep 24 '22 19:09

RobinGower