# How to find a revision's branch name

4 messages from 2006-03-18 to 2006-03-18. Participants: Marco Costalba, Junio C Hamano.
Thread: https://gitlist.dev/t/3668

## Marco Costalba, 2006-03-18 06:02

Subject: How to find a revision's branch name
Message-ID: <e5bfff550603172202ia4b69f2he5562b826e491426@mail.gmail.com>
URL: https://gitlist.dev/e/e5bfff550603172202ia4b69f2he5562b826e491426%40mail.gmail.com

```
In today git archive, todo branch.

$ git-rev-list -n1 --header b14e2494b8a70737066f4ade4df1b5559e81b44b
b14e2494b8a70737066f4ade4df1b5559e81b44b
tree 1baa1f8405d1fef90fe95f2477133a69adec288b
parent 8158d510c641e2354cf24a10bc3e994c7a1e3125
author Junio C Hamano <junkio@cox.net> 1137562948 -0800
committer Junio C Hamano <junkio@cox.net> 1137562948 -0800

    TODO updates 2006-01-17.

    Signed-off-by: Junio C Hamano <junkio@cox.net>


Is it possible to get branch name from a revision sha?
Something like

$ git branch b14e2494b8a70737066f4ade4df1b5559e81b44b
todo

I need this to correctly annotate files not in HEAD tree. Currently qgit runs
git-rev-list --header --topo-order --parents --remove-empty HEAD -- <path>

to get a file history. But this fails if <path> is not found in HEAD. The right
command to run in our case should be:
git-rev-list --header --topo-order --parents --remove-empty todo -- <path>

So I need to get 'todo' branch name from a given revision sha's.

BTW also git blame fails (gracefully) if revision is not in HEAD:

$ git blame b14e2494b8a70737066f4ade4df1b5559e81b44b
b14e2494b8a70737066f4ade4df1b5559e81b44b not found in HEAD


Thanks
Marco

```

## Junio C Hamano, 2006-03-18 06:37

Subject: Re: How to find a revision's branch name
Message-ID: <7vfylgz29x.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vfylgz29x.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <e5bfff550603172202ia4b69f2he5562b826e491426@mail.gmail.com>

```
Marco Costalba <mcostalba@gmail.com> writes:

> Is it possible to get branch name from a revision sha?
> Something like
>
> $ git branch b14e2494b8a70737066f4ade4df1b5559e81b44b
> todo

That is in general impossible.

        $ git show-branch master~1 next pu
        ! [master~1] blame: Nicer output
         ! [next] Merge branch 'jc/cvsimport' into next
          ! [pu] Merge branch 'jc/cvsimport' into next
        ---
         -- [next] Merge branch 'jc/cvsimport' into next
         ++ [next^2] cvsimport: honor -i and non -i upon subsequent
         imports
         -- [next^] Merge branch 'jc/fetch' into next
         ++ [next^^2] fetch: exit non-zero when fast-forward check
         fails.
         -- [next~2] Merge branch 'ew/abbrev' into next
         ++ [next~2^2] ls-files: add --abbrev[=<n>] option
         ++ [next~2^2^] ls-tree: add --abbrev[=<n>] option
         ++ [next^2^] blame: Fix git-blame <directory>
        +++ [master~1] blame: Nicer output
        $ git rev-parse --verify master~1
        88a8b7955666ed8fa5924fadbb3bb58984eaa6af

Now what should this command say?

        $ git branch --tell 88a8b7955666ed8fa5924fadbb3bb58984eaa6af

It is not head of any branch.  Should it say master~1?
next^2~1?  pu^2~1?

The closest thing is name-rev, which tries to give you the
simplest.  It may or may not match what you want:

        $ git name-rev 88a8b7955666ed8fa5924fadbb3bb58984eaa6af
        88a8b7955666ed8fa5924fadbb3bb58984eaa6af master~1
        $ git name-rev `git rev-parse --verify b14e24`
        b14e2494b8a70737066f4ade4df1b5559e81b44b todo~16

However.

> I need this to correctly annotate files not in HEAD
> tree. Currently qgit runs git-rev-list --header --topo-order
> --parents --remove-empty HEAD -- <path>
>
> to get a file history. But this fails if <path> is not found
> in HEAD. The right command to run in our case should be:
> git-rev-list --header --topo-order --parents --remove-empty
> todo -- <path>

... I wonder why you care.  Wouldn't this work just as well?

	$ git rev-list --header --topo-order --parents --remove-empty \
	  --all -- <path>

It lists 70 commits at the moment.

```

## Marco Costalba, 2006-03-18 07:35

Subject: Re: How to find a revision's branch name
Message-ID: <e5bfff550603172335v11ea36a8j9cca2ed2df58b45d@mail.gmail.com>
URL: https://gitlist.dev/e/e5bfff550603172335v11ea36a8j9cca2ed2df58b45d%40mail.gmail.com
In-Reply-To: <7vfylgz29x.fsf@assigned-by-dhcp.cox.net>

```
On 3/18/06, Junio C Hamano <junkio@cox.net> wrote:
> Marco Costalba <mcostalba@gmail.com> writes:
>
> > Is it possible to get branch name from a revision sha?
> > Something like
> >
> > $ git branch b14e2494b8a70737066f4ade4df1b5559e81b44b
> > todo
>
> That is in general impossible.
>

>
> > I need this to correctly annotate files not in HEAD
> > tree. Currently qgit runs git-rev-list --header --topo-order
> > --parents --remove-empty HEAD -- <path>
> >
> > to get a file history. But this fails if <path> is not found
> > in HEAD. The right command to run in our case should be:
> > git-rev-list --header --topo-order --parents --remove-empty
> > todo -- <path>
>
> ... I wonder why you care.  Wouldn't this work just as well?
>
>         $ git rev-list --header --topo-order --parents --remove-empty \
>           --all -- <path>
>

Yessss!!!

Thanks for the fix. I missed that.

Marco

```

## Junio C Hamano, 2006-03-18 08:31

Subject: Re: How to find a revision's branch name
Message-ID: <7v64mcxig1.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7v64mcxig1.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <e5bfff550603172335v11ea36a8j9cca2ed2df58b45d@mail.gmail.com>

```
Marco Costalba <mcostalba@gmail.com> writes:

>> ... I wonder why you care.  Wouldn't this work just as well?
>>
>>         $ git rev-list --header --topo-order --parents --remove-empty \
>>           --all -- <path>
>>
>
> Yessss!!!

I think I spoke too early.  I think --remove-empty does not
prevent rev-list from traversing branches that <path> _never_
appears in their history, so if the <path> given was TODO, it
will go all the way back to the very first commit by Linus, and
the very first commit for gitk by Paul, without finding a commit
that touches that file.

One option is "--remove-empty --all" with <path> to omit heads
and tags that do _not_ have given <path>s from the set of
starting points, but then you cannot grab history of rev-tree.c
between v0.99.7 and 9dcc829 (v0.99.7 was the last tagged commit
that had rev-tree.c, but removal of the file happened 39 commits
after that), so that is not really an option.

I guess we need to live with this; git.git repository is quite
special.  If you clone from it, you would get todo, html and man
branches, so it *appears* that these are part of the same
repository, but logically these branches are not part of the
project history proper.

The commits that belong to these three branches do not appear in
my private development repository.  The todo branch is pushed
into git.git from a completely separate repository from my side,
and html and man branches are pushed from other separate
repositories of their own on a kernel.org machine, automatically
built after I push new stuff into the "master" branch of git.git
repository, by the post-update hook.

The only reason I have these three branches in git.git
repository is historical.  I do not have write access on
kernel.org machine in /pub/scm/git itself. I can only write in
/pub/scm/git/git.git/, and I never bothered to ask the operators
to make /pub/scm/git itself writable by me; otherwise I would
have made /pub/scm/git/git-{todo,html,man}.git repositories.

```
