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

Re: Re: git rev-list ordering

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Nov 17, 2008, 01:35 UTC
Message-ID
<alpine.DEB.1.00.0811170231430.30769@pacific.mpi-cbg.de>
In-Reply-To
<alpine.LFD.2.00.0811162001550.28544@sys-0.hiltweb.site>
Hi,
On Sun, 16 Nov 2008, Ian Hilt wrote:
Show 28 quoted lines
> On Sun, 16 Nov 2008, Johannes Schindelin wrote:
> 
> > On Sat, 15 Nov 2008, Ian Hilt wrote:
> > 
> > > On Sat, 15 Nov 2008, Sverre Rabbelier wrote:
> > > > The --reverse is applied after the --max-count, so you are seeing 
> > > > the reverse of one commit ;). For comparison, have a look at:
> > > > 
> > > > $ git rev-list --reverse --max-count=2
> > > 
> > > Ah, I see.  So if you didn't want the sorting to take a long time 
> > > for many commits, you would limit the output to n commits, then sort 
> > > the output.  Is this the logic behind this design?
> > 
> > Yes.  It is by design, since the guy who wrote the initial --reverse 
> > support cannot think of an interesting situation where you need to 
> > list the oldest n commits.
> 
> I see.  Well, the situation in which I found this to be needed was while 
> trying to figure out how to find the next commit on branch X while on a 
> detached head from that branch without counting how many commits back I 
> was.  In other words,
> 
> $ git checkout X~4
> $ # now I want X~3 without using a number or carets
> $ git checkout $(git rev-list --reverse ..X | head -1)
>  -- or --
> $ git checkout $(git rev-list ..X | tail -1)

This could break down horribly when there was branching going on. However, in case you are certain there is only one child of X~4, I'd suggest doing this:

$ git checkout $(git rev-list --parents --all ^HEAD |
	sed -n "s/ .*$(git rev-parse HEAD).*$//p")

IOW I would list all revisions with parents, and filter out all which do not have the current one as parent.

Hth, Dscho

Previous: Ian HiltNext: Pete Harlan
Message 6 of 8 in “git rev-list ordering”
  1. Ian HiltNov 16, 2008
  2. Sverre RabbelierNov 16, 2008
  3. Ian HiltNov 16, 2008
  4. Johannes SchindelinNov 16, 2008
  5. Ian HiltNov 17, 2008
  6. Johannes SchindelinNov 17, 2008
  7. Pete HarlanNov 18, 2008
  8. Björn SteinbrinkNov 19, 2008

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.