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

Re: Find out on which branch a commit was originally made

From
ASArtur Skawina <art.08.09@gmail.com>
Date
Sep 19, 2010, 23:12 UTC
Message-ID
<4C9698C5.70607@gmail.com>
In-Reply-To
<201009192203.o8JM39PE011067@no.baka.org>
On 09/20/10 00:03, Seth Robertson wrote:
Show 18 quoted lines
>>>>                A---B---C topic
>>>>               /         \
>>>>          D---E---F---G---H---I---J---K---L---M---N master
>>>>                                   \         /
>>>>                                    O---P---Q another-topic
> 
>>> No, that's not what I need either.  After thinking about it more, I
>>> think what I want is "of all merges in the ancestry path from B to
>>> master, show only those whose first parent can't reach B."  The result
>>> is the list of all merges that were involved in bringing B to master.
> 
> 
>> This would work, and i don't see a way to optimize it in git-speak,
>> given that you don't want to see any extra trailing merges. [...]
> 
> The provided command actually doesn't work for me for all cases.  It
> works for the simple case of "B", but does not work for "F", because F
> saw merge H & M.  I think we need --not --first-parent, except that

Well, F was never on a separate branch, so the command returning "" is arguably the right thing. The example I gave (B->[merge of subtopic]->[merged to supertopic]->[merged to master]) was the case where "--not-first-parent" wouldn't help, even if such an option would exist.

Show 13 quoted lines
> doesn't actually work in this case either.  However, if we get the
> full --first-parent rev-list and look for our commit, that works.
> This is incredibly painful, though.
> ----------------------------------------------------------------------
> #!/bin/sh
> TARGET=`git rev-list -n 1 $1`
> git branch -a --contains $1 | sed 's/^\** *//' | grep -v ' -> ' |
> while read br; do
>  if git rev-list --first-parent $br | grep -q "$TARGET"; then
>   echo $br
>  fi
> done
> ----------------------------------------------------------------------
And it does not work if you no longer have the branches around...

But even if you kept all the old refs, this would return "another-topic"+"master", which is hardly the right answer.

artur
Previous: Seth RobertsonNext: Seth Robertson
Message 14 of 33 in “Find out on which branch a commit was originally made”
  1. Stefan HallerSep 18, 2010
  2. Ævar Arnfjörð BjarmasonSep 18, 2010
  3. Ævar Arnfjörð BjarmasonSep 18, 2010
  4. Tor ArntsenSep 18, 2010
  5. Stefan HallerSep 18, 2010
  6. Artur SkawinaSep 18, 2010
  7. Stefan HallerSep 19, 2010
  8. Clemens BuchacherSep 19, 2010
  9. Artur SkawinaSep 19, 2010
  10. Stefan HallerSep 19, 2010
  11. Artur SkawinaSep 19, 2010
  12. Robin RosenbergSep 19, 2010
  13. Seth RobertsonSep 19, 2010
  14. Artur SkawinaSep 19, 2010
  15. Seth RobertsonSep 19, 2010
  16. Artur SkawinaSep 20, 2010
  17. Seth RobertsonSep 20, 2010
  18. Stefan HallerSep 20, 2010
  19. Artur SkawinaSep 20, 2010
  20. Artur SkawinaSep 20, 2010
  21. Seth RobertsonSep 21, 2010
  22. Artur SkawinaSep 21, 2010
  23. ANNOUNCE git-what-branch (was Re: Find out on which branch a commit was originally made)Seth Robertson, Sep 22, 2010
  24. Artur SkawinaSep 22, 2010
  25. Seth RobertsonSep 22, 2010
  26. Stephen BashSep 23, 2010
  27. Ævar Arnfjörð BjarmasonSep 23, 2010
  28. Artur SkawinaSep 23, 2010
  29. Artur SkawinaSep 24, 2010
  30. Seth RobertsonSep 24, 2010
  31. Seth RobertsonSep 23, 2010
  32. Stefan HallerSep 20, 2010
  33. Bryan DrewerySep 24, 2010

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.