From: Jeff King <peff@peff.net>
To: Robert Dailey <rcdailey.lists@gmail.com>
Cc: Git <git@vger.kernel.org>
Subject: Re: How can I get a list of checkout history?
Date: Mon, 15 Feb 2016 11:56:03 -0500 [thread overview]
Message-ID: <20160215165603.GD25364@sigill.intra.peff.net> (raw)
In-Reply-To: <CAHd499D5nMvFQ-eok_3tMZTNp+9JdcMZSL9XrXqkdUNxmRq_eQ@mail.gmail.com>
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
prev parent reply other threads:[~2016-02-15 16:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-15 15:18 How can I get a list of checkout history? Robert Dailey
2016-02-15 16:56 ` Jeff King [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160215165603.GD25364@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=rcdailey.lists@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).