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

Re: Listing of branch creation time?

From
Jeff King <peff@peff.net>
Date
Mar 27, 2007, 23:35 UTC
Message-ID
<20070327233552.GA7186@coredump.intra.peff.net>
In-Reply-To
<17929.37382.984339.742025@lisa.zopyra.com>
On Tue, Mar 27, 2007 at 03:52:06PM -0600, Bill Lear wrote:
Show 6 quoted lines
> I'm sure the git developers grow tired of working with addle-brained
> users, but I sometimes forget what the contents of a topic branch are,
> how old it is, etc.  As to content, I can make better branch names,
> but I think it would be useful to be able to query git as to the
> creation time of all of my branches, perhaps sorted from newest to
> oldest.

I'm not sure you can always accurately get that information. If you have reflogs turned on, you can look at the oldest reflog for the that ref; however, the reflog may have been pruned. You can also try looking at the commit graph, but then you need a reference branch ("when did I branch from master"), and even that's not entirely useful. You have to look at the latest merge-base, but that tells you the last time you merged with master, not necessarily the first time.

That being said, something like this should work:

-- >8 -- #!/bin/sh

branch_date() {
  git-rev-list -g --pretty=format:'%ct %cd' $1 | tail -n 1
}
git-show-ref --heads |
  while read sha1 branch; do
    echo "$branch `branch_date $branch`"
  done |
  sort -k 2nr |
  while read branch timestamp date; do
    printf '%20s %s\n' ${branch#refs/heads/} "$date"
  done
-- >8 --

Unfortunately, there is a bug in git-rev-list; I've just posted a patch, but the one-liner fix is:

diff --git a/commit.c b/commit.c
index 718e568..a92958c 100644
--- a/commit.c
+++ b/commit.c
@@ -760,7 +760,7 @@ static void fill_person(struct interp *table, const char *msg, int len)
 	if (msg + start == ep)
 		return;
 
-	table[5].value = xstrndup(msg + start, ep - msg + start);
+	table[5].value = xstrndup(msg + start, ep - (msg + start));
 
 	/* parse tz */
 	for (start = ep - msg + 1; start < len && isspace(msg[start]); start++)

With that fix, the script above should hopefully produce what you want.

-Peff
Previous: Johannes SchindelinNext: Bill Lear
Message 5 of 17 in “Listing of branch creation time?”
  1. Bill LearMar 27, 2007
  2. git-branch: add --sort-by-date optionJohannes Schindelin, Mar 27, 2007
  3. Bill LearMar 27, 2007
  4. Teach revision machinery about --no-walkJohannes Schindelin, Jul 23, 2007
  5. Jeff KingMar 27, 2007
  6. Bill LearMar 28, 2007
  7. Jeff KingMar 28, 2007
  8. Bill LearMar 28, 2007
  9. Jeff KingMar 28, 2007
  10. Bill LearMar 28, 2007
  11. David LangMar 27, 2007
  12. Jeff KingMar 28, 2007
  13. Nicolas PitreMar 28, 2007
  14. Nicolas PitreMar 28, 2007
  15. Linus TorvaldsMar 28, 2007
  16. Junio C HamanoMar 28, 2007
  17. Jeff KingMar 28, 2007

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.