git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [Question] How to know which branch(ref) is the latest updated branch?
@ 2022-08-18 10:04 lilinchao
  2022-08-18 14:30 ` Dan Pristupov
  2022-08-18 17:08 ` Junio C Hamano
  0 siblings, 2 replies; 3+ messages in thread
From: lilinchao @ 2022-08-18 10:04 UTC (permalink / raw)
  To: git

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?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Question] How to know which branch(ref) is the latest updated branch?
  2022-08-18 10:04 [Question] How to know which branch(ref) is the latest updated branch? lilinchao
@ 2022-08-18 14:30 ` Dan Pristupov
  2022-08-18 17:08 ` Junio C Hamano
  1 sibling, 0 replies; 3+ messages in thread
From: Dan Pristupov @ 2022-08-18 14:30 UTC (permalink / raw)
  To: lilinchao@oschina.cn, git

You can use `for-each-ref` for that. For example:

```
git for-each-ref --count=1 --sort='-authordate' refs/heads
```

https://git-scm.com/docs/git-for-each-ref#_examples has an example how 
to get 3 recent tags


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Question] How to know which branch(ref) is the latest updated branch?
  2022-08-18 10:04 [Question] How to know which branch(ref) is the latest updated branch? lilinchao
  2022-08-18 14:30 ` Dan Pristupov
@ 2022-08-18 17:08 ` Junio C Hamano
  1 sibling, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2022-08-18 17:08 UTC (permalink / raw)
  To: lilinchao; +Cc: git

"lilinchao@oschina.cn" <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).

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-08-18 17:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-18 10:04 [Question] How to know which branch(ref) is the latest updated branch? lilinchao
2022-08-18 14:30 ` Dan Pristupov
2022-08-18 17:08 ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).