From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_CSS,URIBL_CSS_A shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by dcvr.yhbt.net (Postfix) with ESMTP id 7CF941F59D for ; Thu, 18 Aug 2022 17:16:23 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (1024-bit key; unprotected) header.d=pobox.com header.i=@pobox.com header.b="j/4wSpb/"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345520AbiHRRQP (ORCPT ); Thu, 18 Aug 2022 13:16:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345032AbiHRRP5 (ORCPT ); Thu, 18 Aug 2022 13:15:57 -0400 Received: from pb-smtp2.pobox.com (pb-smtp2.pobox.com [64.147.108.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7E2D61104 for ; Thu, 18 Aug 2022 10:08:42 -0700 (PDT) Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 7206614C855; Thu, 18 Aug 2022 13:08:21 -0400 (EDT) (envelope-from junio@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=/yTVRiCbUUfJukT2yOBfvUHOrZH5SD8iP5Q/sq xp0JA=; b=j/4wSpb//uOu4PxOFRPv1Hp7oC3PMBu/P628ILg7bRXbdQKuXUk1Me +OX3BIGGW1q396G9SbVZCe1/83gx7Hj4bz2AcAOgZJMZP5/eNlrtRbKZQP/YG6JF PH0bjAJQPY7KegWxLbmnTER7ZK64aunOJRkzCb0UkpQqhRVAdVaNg= Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 6936A14C854; Thu, 18 Aug 2022 13:08:21 -0400 (EDT) (envelope-from junio@pobox.com) Received: from pobox.com (unknown [34.83.5.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id C28E614C853; Thu, 18 Aug 2022 13:08:20 -0400 (EDT) (envelope-from junio@pobox.com) From: Junio C Hamano To: lilinchao@oschina.cn Cc: git Subject: Re: [Question] How to know which branch(ref) is the latest updated branch? References: <2022081818034939145210@oschina.cn> Date: Thu, 18 Aug 2022 10:08:19 -0700 In-Reply-To: <2022081818034939145210@oschina.cn> (lilinchao@oschina.cn's message of "Thu, 18 Aug 2022 18:04:49 +0800") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Pobox-Relay-ID: 5C64DB7E-1F18-11ED-8A93-CB998F0A682E-77302942!pb-smtp2.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org "lilinchao@oschina.cn" writes: > In a git based workflow, there are usually many active branches. > So, is there a convenient way to quickly know which branch is the > latest updated? These days "git branch" has "--sort" option, inherited from "for-each-ref", so git branch --sort=-committerdate lists them from the most-recently-committed [*]. HOWEVER. There is no way to sort on the time when each branch was last updated. You may do git branch newbranch HEAD@{2.years.ago} to create a new branch (i.e. it is the last updated branch) that points at a commit that existed 2 years ago (hence it would be at least 2 years old, possibly more). If for-each-ref learns a new placeholder %(reflogtime) that can be used to represent the timestamp of the latest reflog entry, you should be able to sort by the time when branch was last updated, but not until then. [Footnote] I have this handy alias [alias] notyet = branch --no-merged jch --no-merged seen --sort=-committerdate '??/*' to remind me of topics that are not yet in my integration branches while rebuilding them. In the end result, 'seen' is supposed to include "everything I saw and found possibly interesting", and 'jch' is supposed to be a subset of it, but explicitly saying "show branches that are not in either of these two" helps while rebuilding them (and I do so a few times a day).