git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Adding files to a git-archive when it is generated, and whats the best way to find out what branch a commit is on?

From
SBSanti Béjar <santi@agolina.net>
Date
Jul 29, 2009, 11:13 UTC
Message-ID
<adf1fd3d0907290413x4aa0d091ldb651537a101a2f8@mail.gmail.com>
In-Reply-To
<9b18b3110907290251t4d8c83d3rf12d0ea9268c19bd@mail.gmail.com>
2009/7/29 demerphq <demerphq@gmail.com>:
Show 36 quoted lines
> 2009/7/29 Santi Béjar <santi@agolina.net>:
>> 2009/7/29 demerphq <demerphq@gmail.com>:
>>> 2009/7/29 Santi Béjar <santi@agolina.net>:
>>>> 2009/7/29 demerphq <demerphq@gmail.com>:
>>>>> Another question is whether anyone has any advice on the best way to
>>>>> find out the "best" branch an arbitrary commit is on. Where best can
>>>>> be flexibly definied to handle commits that are reachable from
>>>>> multiple branches.  I have hacked a solution involving git-log and
>>>>> grep, but it performs quite poorly. I was wondering if there is a
>>>>> better solution.
>>>>
>>>> The "best" tag is easy: git describe commit. For branches I think you
>>>> could use "git name-ref --refs=refs/heads/* commit", because git
>>>> describe does not have a --branches flag.
>>>
>>> Dang, I guess this is from a newer release than mine. So now i have an
>>> excuse to upgrade.
>>
>> No, it is quite old (the --refs flag since the v1.5.1). If the problem
>> is that you don't find the "git name-ref" command is because it is
>> "git name-rev", oops.
>
> Dang, guess i need a different excuse. :-)
>
> But it doesn't seem to do what i need:
>
> $ git name-rev --refs=refs/heads/* faa7dc9f4d3a618b0ad8b3c95edd54e24c6976e7
> faa7dc9f4d3a618b0ad8b3c95edd54e24c6976e7 undefined
>
> But i think that just because in this case I need remote refs:
>
> git name-rev --refs=refs/remotes/* faa7dc9f4d3a618b0ad8b3c95edd54e24c6976e7
> faa7dc9f4d3a618b0ad8b3c95edd54e24c6976e7 remotes/origin/maint-5.005~25
>
> Which is definitely better. Can I safely strip the ~25 off the end to
> get the real branch name?

Yes, it describes the relation between both, you can strip everything after ^ or ~ (and you can use the --name-only to remove the sha1).

HTH, Santi

Previous: demerphqNext: René Scharfe
Message 7 of 14 in “Adding files to a git-archive when it is generated, and whats the best way to find out what branch a commit is on?”
  1. demerphqJul 29, 2009
  2. Avery PennarunJul 29, 2009
  3. Santi BéjarJul 29, 2009
  4. demerphqJul 29, 2009
  5. Santi BéjarJul 29, 2009
  6. demerphqJul 29, 2009
  7. Santi BéjarJul 29, 2009
  8. René ScharfeJul 30, 2009
  9. demerphqJul 31, 2009
  10. René ScharfeAug 2, 2009
  11. demerphqAug 2, 2009
  12. René ScharfeAug 4, 2009
  13. Jeff EplerJul 29, 2009
  14. demerphqJul 31, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.