{"thread":{"id":"41415","subject":"How can I get a list of checkout history?","startedAt":"2016-02-15T15:18:50Z","lastAt":"2016-02-15T16:56:03Z","messageCount":2,"participants":["Robert Dailey","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"278165","messageId":"CAHd499D5nMvFQ-eok_3tMZTNp+9JdcMZSL9XrXqkdUNxmRq_eQ@mail.gmail.com","threadId":"41415","inReplyTo":null,"subject":"How can I get a list of checkout history?","fromName":"Robert Dailey","fromEmail":"rcdailey.lists@gmail.com","sentAt":"2016-02-15T15:18:50Z","receivedAt":"2016-02-15T15:18:50Z","isPatch":false,"sender":{"key":"rcdailey.lists@gmail.com","avatar":null},"body":"As you know, I can checkout the Nth checked out branch via this syntax:\n\n$ git checkout @{-N}\n\nIs there a built-in mechanism to get a listing of previously checked\nout refs? Basically, this would be similar to 'history' command in\nlinux where instead of actual commands, it lists like this:\n\nHEAD@{-1}: master\nHEAD@{-2}: topic1\nHEAD@{-3}: 3f556e9 (detached)\n\nSeems like reflog should be able to do this, and maybe it can, but I'm\nnot sure. Any tips? I'd be fine making a convenient alias for this if\nit ends up being a series of piped commands.\n\nThanks in advance.\n"},{"id":"278166","messageId":"20160215165603.GD25364@sigill.intra.peff.net","threadId":"41415","inReplyTo":"CAHd499D5nMvFQ-eok_3tMZTNp+9JdcMZSL9XrXqkdUNxmRq_eQ@mail.gmail.com","subject":"Re: How can I get a list of checkout history?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2016-02-15T16:56:03Z","receivedAt":"2016-02-15T16:56:03Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Feb 15, 2016 at 09:18:50AM -0600, Robert Dailey wrote:\n\n> As you know, I can checkout the Nth checked out branch via this syntax:\n> \n> $ git checkout @{-N}\n> \n> Is there a built-in mechanism to get a listing of previously checked\n> out refs? Basically, this would be similar to 'history' command in\n> linux where instead of actual commands, it lists like this:\n> \n> HEAD@{-1}: master\n> HEAD@{-2}: topic1\n> HEAD@{-3}: 3f556e9 (detached)\n> \n> Seems like reflog should be able to do this, and maybe it can, but I'm\n> not sure. Any tips? I'd be fine making a convenient alias for this if\n> it ends up being a series of piped commands.\n\nThe \"@{-N}\" syntax works by reading the HEAD reflog backwards and\ngrepping for \"checkout: moving from ...\". The implementation is in\ngrab_nth_branch_switch.\n\nYou could do it yourself like:\n\n  git reflog HEAD |\n  perl -lne '/checkout: moving from (\\S+) to/ and print $1'\n\nThat includes detached HEADs, too. If you want just \"real\" branaches,\nyou could possibly omit entries which match [0-9a-f]{40}. But that's\njust a heuristic (you _could_ have a branch that matches that).\n\n-Peff\n"}]}