Reputation: 89
I am using the below GIT command to extract the list of branches along with committer name and date. But, wanted to know how to get the branches that were older than 90 days instead of getting the entire list.
git for-each-ref --count=10 --sort=-committerdate refs/remotes/ --format='%(refname:short) = %(committerdate:short) =%(committername) =%(authorname)'| xargs -L1 | cut -d"/" -f2- >> $allbrancheslist.txt
Upvotes: 4
Views: 2417
Reputation: 1330092
git log -1 --pretty=%cd --date=format:%s ${commit}
The OP mentions in the comments:
Getting the below error while trying the execute the provided script date: extra operand ‘%s’ Try 'date --help' for more information. fatal: invalid strftime format: '%s'
That means Windows, and this is fixed with Git 2.27 (Q2 2020).
See commit 3efc128 (09 Apr 2020), and commit b6852e1 (08 Apr 2020) by Johannes Schindelin (dscho
).
See commit a748f3f (08 Apr 2020) by Matthias Aßhauer (rimrul
).
(Merged by Junio C Hamano -- gitster
-- in commit b3eb70e, 22 Apr 2020)
mingw
: use modern strftime implementation if possibleSigned-off-by: Matthias Aßhauer
Signed-off-by: Johannes SchindelinMicrosoft introduced a new "Universal C Runtime Library" (
UCRT
) with Visual Studio 2015.
The UCRT comes with a newstrftime()
implementation that supports more date formats.
We link git against the older "Microsoft Visual C Runtime Library" (MSVCRT), so to use theUCRT strftime()
we need to load it fromucrtbase.dll
usingDECLARE_PROC_ADDR()/INIT_PROC_ADDR()
.Most supported Windows systems should have received the UCRT via Windows update, but in some cases only MSVCRT might be available.
In that case we fall back to using that implementation.With this change, it is possible to use e.g. the
%g
and%V
date format specifiers, e.g.git show -s --format=%cd --date=format:‘%g.%V’ HEAD
Without this change, the user would see this error message on Windows:
fatal: invalid strftime format: '‘%g.%V’'
This fixes
git-for-windows/git
issue 2495 "Missing support for ISO 8601 date formats"
Upvotes: 1
Reputation: 30986
#!/bin/bash
# 90 days = 7776000 seconds
INTERVAL=7776000
git for-each-ref refs/remotes | while read commit type ref;do
current=$(date +%s)
headcd=$(git log -1 --pretty=%cd --date=format:%s ${commit})
if [[ $((current-headcd)) -ge ${INTERVAL} ]];then
echo $ref
fi
done
Get the current date and the commit date of each ref's head in the format of epoch. Calculate the interval and print the refs whose interval is greater than or equal to 7776000 seconds.
Upvotes: 3