From: Jeff King Date: Thu, 18 Nov 2010 16:13:51 GMT Subject: Re: [PATCH] branch: support sorting branches by mtime Message-ID: <20101118161351.GA19011@sigill.intra.peff.net> In-Reply-To: <1290090126-14471-1-git-send-email-pclouds@gmail.com> On Thu, Nov 18, 2010 at 09:22:06PM +0700, Nguyễn Thái Ngọc Duy wrote: > I lost in my branches again while looking for a topic that I feel like > working on tonight. Too old branches are out of question. > > This throwaway patch demonstrates the idea. I should have looked into > reflog for this kind of information, but my laziness won over me. I do something similar, but rather than using mtime, I sort by authordate, which for-each-ref supports already. In fact, the script I use is: -- >8 -- #!/bin/sh format='%(refname:short)' sortby=refname set -- $(getopt vt "$@") while test $# -gt 0; do case "$1" in -v) format='%(refname:short) %(subject)' ;; -t) sortby=-authordate ;; --) break ;; *) echo >&2 "unknown option: $1"; exit 100 ;; esac shift done git for-each-ref --sort=$sortby --format="$format" refs/heads | egrep '^[a-z]{2,3}/' | perl -pe ' s/(\S+) /$1 . " " x (22 - length($1))/e; # line up subjects s/^(.{79}).*/$1/; # truncate long lines ' -- 8< -- It might be nice if git-branch supported the same sortby that for-each-ref does. -Peff