[ACCEPTED]-How to tell which branch a github commit was for?-github

Accepted answer
Score: 11

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

Score: 10

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

git branch --contains <commit>

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

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

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

enter image description here

Score: 4

From git help branch:

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

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

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

Score: 3

If it's a fairly recent commit, you can 8 go to your network graph (e.g., https://github.com/BenHocking/ShortCircuitGA/network) and hover 7 over each node on a branch until you find 6 the commit you're looking for. It's not 5 efficient, but it's the only way I know 4 how to do it directly from GitHub. (If 3 you've got SourceTree, GitX, or other visual 2 Git clients, there might be other alternatives, as 1 well as command line alternatives.)

Score: 1

Start to submit a pull request for the commit. You'll 1 see the default source branch on the "from" side.

Score: 0

This answer won't help for previous check-ins, but 3 I use the following commit-msg hook script 2 to append the current branch to every commit 1 message.

export BRANCH=`git status | head -1 | cut -c13-`
echo -n "($BRANCH) - " > .git/tmp-msg
cat $1 >> .git/tmp-msg
mv .git/tmp-msg $1

exit 0

More Related questions