An Interest In:
Web News this Week
- March 22, 2024
- March 21, 2024
- March 20, 2024
- March 19, 2024
- March 18, 2024
- March 17, 2024
- March 16, 2024
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
Original Link: https://dev.to/abdlrahmansaberabdo/how-view-branches-sorted-by-date-in-specific-format-and-order-34g7
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To