Nambi
Nambi

Reputation: 2717

How to find the branch for a commitId in git?

lets say I have a commit Id "0678dd19c498ede50e7714505eb5af3a5494beef" I tried "git log" command, which prints,

$git log --full-history   1c57338cd62ee1a83df57d2c37ce1f3fa17bee17
commit 1c57338cd62ee1a83df57d2c37ce1f3fa17bee17
Author: [email protected]
Date:   Thu Feb 3 15:39:33 2011 -0800

Updated ejo syntax

commit 8fb7a6b3e44a020e4e495fd1c9a9976c8675c339
Author: [email protected]
Date:   Thu Feb 3 14:49:19 2011 -0800

Added a sample controller

commit 628788eb81c365a88ab435ffa62978077065f72c
Author: [email protected]
Date:   Wed Feb 2 11:33:41 2011 -0800

Test checkin

Is there anyway to print the branch on which this commit is made?

Upvotes: 5

Views: 1602

Answers (2)

twalberg
twalberg

Reputation: 62489

After digging around a bit in the git log manual page, I came up with this, that I think will work:

git log --all --pretty=oneline --source --since=yesterday

That will list all commits on any branch added since yesterday, along with the name of the branch on which the commit lives. You might get some oddities in the presence of merges and/or new branches, and you may want to pass the output to something like awk '{print $2}' | sort -u to get rid of duplicates.

Upvotes: 0

Dylan Tack
Dylan Tack

Reputation: 745

The command you want is

git branch --contains <commit>

Note that the commit may be contained in multiple branches.

Upvotes: 11

Related Questions