git - 如何在分支名称之前打印 X 个月前的时间?
问题描述
下面的代码我正在尝试,输出应该包含 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
解决方案
current_timestamp=$(date +%s)
four_month_ago=$(( $current_timestamp - 4*30*24*60*60 ))
for x in `git branch -r|sed 's/origin\///'|sed -e '/ HEAD /d'`; do
branch_timestamp=$(git show -s --format=%at origin/$x)
if [[ "$branch_timestamp" < "$four_month_ago" ]]; then
num=$(( ($current_timestamp - $branch_timestamp) / (30*24*60*60)))
list_branch+=("$num month ago - ${x}")
fi
done
i=0
for x in "${list_branch[@]}"; do
printf " %3d - %s\n" $i "$x"
i=$(( i + 1 ))
done
推荐阅读
- linux - 使用 grep 时如何获取查询订单输出?
- python - 从 Jupyter Notebook 显示和保存 PGF 图
- node.js - npm install 完成时播放声音或通知
- javascript - 箱线图上的两个 x 轴
- javascript - 有没有比 for 循环更快的方法来对 javascript 中的图像进行阈值处理?
- angular - ng-bootstrap 分页无法通过 i18n 覆盖“下一个”、“上一个”
- python - Peewee 从一个嵌套字典中获取包含某些列的表
- python - Python:groupby 和聚合 > 添加到原始 df
- php - 在 docker 外调用 Docker 容器
- linux - Odoo 容器:数据库连接失败:无法连接到服务器:连接被拒绝(将 odoo 与 localhost postgres 链接)