下面的代码我正在尝试,输出应该包含 x 个月前的分支名称。此逻辑中的任何建议将不胜感激。
这里代码的主要目的是获取 4 个月前的所有分支名称列表。
current_timestamp=$(date +%s)
four_month_ago=$(( $current_timestamp - 4*30*24*60*60 ))
for x in `git branch -r`; do
branch_timestamp=$(git show -s --format=%at $x)
if [[ "$branch_timestamp" < "$four_month_ago" ]]; then
list_branch+=("${x/origin\//}")
fi
done
i=0
for x in ${list_branch[*]}; do
printf " %3d - %s\n" $i $x
i=$(( i + 1 ))
done
获取输出:
0 - fix-code
1 - bug-read
2 - feature/memcp-fix
我需要在按日期排序的序列号后添加 x 月时间戳
预期输出:
0 - 5 month ago - fix-code
1 - 7 month ago - bug-read
2 - 10 month ago - feature/memcp-fix