git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* How can I get a list of checkout history?
@ 2016-02-15 15:18 Robert Dailey
  2016-02-15 16:56 ` Jeff King
  0 siblings, 1 reply; 2+ messages in thread
From: Robert Dailey @ 2016-02-15 15:18 UTC (permalink / raw)
  To: Git

As you know, I can checkout the Nth checked out branch via this syntax:

$ git checkout @{-N}

Is there a built-in mechanism to get a listing of previously checked
out refs? Basically, this would be similar to 'history' command in
linux where instead of actual commands, it lists like this:

HEAD@{-1}: master
HEAD@{-2}: topic1
HEAD@{-3}: 3f556e9 (detached)

Seems like reflog should be able to do this, and maybe it can, but I'm
not sure. Any tips? I'd be fine making a convenient alias for this if
it ends up being a series of piped commands.

Thanks in advance.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: How can I get a list of checkout history?
  2016-02-15 15:18 How can I get a list of checkout history? Robert Dailey
@ 2016-02-15 16:56 ` Jeff King
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff King @ 2016-02-15 16:56 UTC (permalink / raw)
  To: Robert Dailey; +Cc: Git

On Mon, Feb 15, 2016 at 09:18:50AM -0600, Robert Dailey wrote:

> As you know, I can checkout the Nth checked out branch via this syntax:
> 
> $ git checkout @{-N}
> 
> Is there a built-in mechanism to get a listing of previously checked
> out refs? Basically, this would be similar to 'history' command in
> linux where instead of actual commands, it lists like this:
> 
> HEAD@{-1}: master
> HEAD@{-2}: topic1
> HEAD@{-3}: 3f556e9 (detached)
> 
> Seems like reflog should be able to do this, and maybe it can, but I'm
> not sure. Any tips? I'd be fine making a convenient alias for this if
> it ends up being a series of piped commands.

The "@{-N}" syntax works by reading the HEAD reflog backwards and
grepping for "checkout: moving from ...". The implementation is in
grab_nth_branch_switch.

You could do it yourself like:

  git reflog HEAD |
  perl -lne '/checkout: moving from (\S+) to/ and print $1'

That includes detached HEADs, too. If you want just "real" branaches,
you could possibly omit entries which match [0-9a-f]{40}. But that's
just a heuristic (you _could_ have a branch that matches that).

-Peff

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-02-15 16:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-15 15:18 How can I get a list of checkout history? Robert Dailey
2016-02-15 16:56 ` Jeff King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).