Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 21, 2022 03:13 am GMT

How view branches sorted by date in specific format and order

This a short tutorial from a git tricks series.

Let's know how we can list all branches sorted by date.

View branch sorted by date

display a list of all local branches and sort them based on the date of their last commit.

# sort desc (-committerdate)git branch --sort=-committerdate# sort asc (committerdate)git branch --sort=-committerdate

If youd like to make a custom format you can use for-each-ref with --sort option and --format option to write your format.

git for-each-ref --sort='-committerdate' --format='%(refname)%09%(committerdate)' refs/heads

In the above command, I print the refname first then commitdate in --format option the output will be like this

refs/heads/branch_name commitdaterefs/heads/branch_name2 commitdate# real outputrefs/heads/new_design   Wed Apr 20 12:24:21 2022 +0200refs/heads/design_assets        Wed Apr 20 11:30:30 2022 +0200

If you want to print the date first then refname, the option format will be like this --format='%(committerdate)%09%(refname)%'

Lets say you dont want to print refs/heads and want print just the branch name each time, how we can do this? by using sed.

git for-each-ref --sort='-committerdate' --format='%(refname)%09%(committerdate)' refs/heads | sed 's-refs/heads/--'#outputbranch_name commitdatebranch_name2 commitdate#real outputnew_design      Wed Apr 20 12:24:21 2022 +0200design_assets   Wed Apr 20 11:30:30 2022 +0200

I find these commands incredibly helpful when returning to work from a weekend or just jumping from project to project. Hopefully, you can use these commands too!

If you found this post useful please share it with your friends

Lets connect on LinkedIn, Twitter


Original Link: https://dev.to/abdlrahmansaberabdo/how-view-branches-sorted-by-date-in-specific-format-and-order-34g7

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To