我使用下面的GIT命令提取分支列表以及提交者名称和日期。但是,想知道如何获得超过90天的分支,而不是获得整个列表。
git for-each-ref --count=10 --sort=-committerdate refs/remotes/ --format='%(refname:short) = %(committerdate:short) =%(committername) =%(authorname)'| xargs -L1 | cut -d"/" -f2- >> $allbrancheslist.txt
#!/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
以epoch的格式获取每个裁判头部的当前日期和提交日期。计算时间间隔并打印时间间隔大于或等于7776000秒的参考值。
git log -1 --pretty=%cd --date=format:%s ${commit}
OP在评论中提到:
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'
这意味着Windows,Git 2.27(2020年第二季度)修复了这一问题。
参见Johannes Schindelin(dscho
)的提交3efc128(2020年4月9日)和提交b6852e1(2020年04月08日)
请参阅Matthias Aßhauer(rimrul
)提交的a748f3f(2020年4月8日)
(由Junio C Hamano合并——gitster
——于2020年4月22日提交b3eb70e)
mingw
:如果可能,请使用现代strftime实现签字人:Matthias Aßhauer
签名人:Johannes SchindelinMicrosoft在Visual Studio 2015中引入了一个新的">通用C运行库"(
UCRT
)。
UCRT附带了一个支持更多日期格式的新strftime()
实现
我们将git链接到旧的"Microsoft Visual C运行库"(MSVCRT),因此要使用UCRT strftime()
,我们需要使用DECLARE_PROC_ADDR()/INIT_PROC_ADDR()
从ucrtbase.dll
加载它。大多数受支持的Windows系统都应该通过Windows更新接收到UCRT,但在某些情况下,可能只有MSVCRT可用
在这种情况下,我们将重新使用该实现。通过此更改,可以使用例如
%g
和%V
日期格式说明符,例如git show -s --format=%cd --date=format:‘%g.%V’ HEAD
如果没有此更改,用户将在Windows:上看到此错误消息
fatal: invalid strftime format: '‘%g.%V’'
这修复了
git-for-windows/git
问题2495"缺少对ISO 8601日期格式的支持">