threads / discuss / 3954

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

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

## tl;dr

4 messages between Apr 24, 2006 and Apr 24, 2006.

replies: 3people: 3as markdown or json

Martin Langhoff· Apr 24, 2006, 04:23 UTC · lore

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· Apr 24, 2006, 04:40 UTC · re: Martin Langhoff · lore

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

"Martin Langhoff" <martin.langhoff@gmail.com> writes:
Show 7 quoted lines
> 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".

Martin Langhoff· Apr 24, 2006, 04:50 UTC · re: Junio C Hamano · lore

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

On 4/24/06, Junio C Hamano <junkio@cox.net> wrote:
Show 5 quoted lines
> 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
Jeff King· Apr 24, 2006, 04:41 UTC · re: Martin Langhoff · lore

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

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

← back to recent threads