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?
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.
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.)
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.
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.
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With