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

Re: [PATCH] branch: support sorting branches by mtime

From
Jeff King <peff@peff.net>
Date
Nov 18, 2010, 16:13 UTC
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:
Show 5 quoted lines
> 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
Previous: Nguyễn Thái Ngọc DuyNext: Joshua Juran
Message 2 of 3 in “branch: support sorting branches by mtime”
  1. branch: support sorting branches by mtimeNguyễn Thái Ngọc Duy, Nov 18, 2010
  2. Jeff KingNov 18, 2010
  3. Joshua JuranNov 20, 2010

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.