# How do I quickly check what heads a particular commit is in?

4 messages from 2006-04-24 to 2006-04-24. Participants: Martin Langhoff, Junio C Hamano, Jeff King.
Thread: https://gitlist.dev/t/3954

## Martin Langhoff, 2006-04-24 04:23

Subject: How do I quickly check what heads a particular commit is in?
Message-ID: <46a038f90604232123r7f35660aufbb9da0f561f8ea@mail.gmail.com>
URL: https://gitlist.dev/e/46a038f90604232123r7f35660aufbb9da0f561f8ea%40mail.gmail.com

```
In the middle of a merge of 2 of a bunch of closely related heads, I
found a few odd things, so I've pickaxe'd and found the (potentially
bogus) commits. I am using gitk, and while I do find the commit, it's
not very clear what heads have the dodgy commit. They've probably been
for a few months in there <sigh>.

Is there a practical way to ask in what heads they are?



martin

```

## Junio C Hamano, 2006-04-24 04:40

Subject: Re: How do I quickly check what heads a particular commit is in?
Message-ID: <7v4q0jd1sj.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7v4q0jd1sj.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <46a038f90604232123r7f35660aufbb9da0f561f8ea@mail.gmail.com>

```
"Martin Langhoff" <martin.langhoff@gmail.com> writes:

> In the middle of a merge of 2 of a bunch of closely related heads, I
> found a few odd things, so I've pickaxe'd and found the (potentially
> bogus) commits. I am using gitk, and while I do find the commit, it's
> not very clear what heads have the dodgy commit. They've probably been
> for a few months in there <sigh>.
>
> Is there a practical way to ask in what heads they are?

git merge-base $broken_commit "master"

would show $broken_commit if "master" is a fast-forward of
$broken_commit (i.e. "master" is a descendant).  I think that is
what you are calling "$broken_commit is in master".

```

## Jeff King, 2006-04-24 04:41

Subject: Re: How do I quickly check what heads a particular commit is in?
Message-ID: <20060424044138.GA20954@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20060424044138.GA20954%40coredump.intra.peff.net
In-Reply-To: <46a038f90604232123r7f35660aufbb9da0f561f8ea@mail.gmail.com>

```
On Mon, Apr 24, 2006 at 04:23:24PM +1200, Martin Langhoff wrote:

> Is there a practical way to ask in what heads they are?

This should work:

$ cat <<'EOF' >find-commit
#!/bin/sh
commit=$1; shift
for i in "$@"; do
  git rev-list $i | fgrep -q $commit && echo $i
done
EOF
$ sh find-commit full-40char-sha1-of-commit head1 head2 ...

You potentially end up traversing parts of the history multiple times
(if they are shared by multiple heads) but git is fast enough that
performance is fine.

I don't know of a way to do it all in a git command without the fgrep.

-Peff

```

## Martin Langhoff, 2006-04-24 04:50

Subject: Re: How do I quickly check what heads a particular commit is in?
Message-ID: <46a038f90604232150y7c99ceb2sf8f6bf05d701b3d7@mail.gmail.com>
URL: https://gitlist.dev/e/46a038f90604232150y7c99ceb2sf8f6bf05d701b3d7%40mail.gmail.com
In-Reply-To: <7v4q0jd1sj.fsf@assigned-by-dhcp.cox.net>

```
On 4/24/06, Junio C Hamano <junkio@cox.net> wrote:
> git merge-base $broken_commit "master"
>
> would show $broken_commit if "master" is a fast-forward of
> $broken_commit (i.e. "master" is a descendant).  I think that is
> what you are calling "$broken_commit is in master".

of course! Thanks! I'm in the middle of a somewhat nasty merge, and my
fingers got all tangled working up and down the history finding what
heads have this commit. I can now do a loop with bash calling all the
heads against it. Great!

 (hmmm. just had to decide to go back to basics and perform some
reverts before retrying the merge.)


m

```
