Re: Listing of branch creation time?
From: Jeff King <hidden>
Date: 2016-06-15 22:43:01
Subsystem:
the rest · Maintainer:
Linus Torvalds
On Tue, Mar 27, 2007 at 03:52:06PM -0600, Bill Lear wrote:
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