git log --before =“ 4个月”向我显示3周前已提交的分支。我究竟做错了什么? [英] git log --before="4 months" show me branches that have commits from 3 weeks ago. what am I doing wrong?

查看:217
本文介绍了git log --before =“ 4个月”向我显示3周前已提交的分支。我究竟做错了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有这个代码段,我想用它来筛选出没有特定前缀并且在3个月内没有收到任何提交的分支,以便以后可以将其从我们的遥控器中删除。

so I have this snippet that I want to use to filter out branches that doesn't have a certain prefix and that hasn't received any commits in over 3 months so that I can remove them from our remote later on.

 for k in $(git branch -r | awk -Forigin !'/\/Prefix1\/|\/prefix2\//'); do
  if [ "$(git log -1 --before="3 month" $k)" ]; then
    echo "$(git log -1 --pretty=format:"%ci, %cr, " $k) $k";
  fi;
done

当前的问题是,当我运行此程序时,我看到已收到提交的分支3周前,5个月前,2个月前,1个月前,依此类推,我不知道为什么。

The problem is currently that when I run this I see branches that have received commits 3 weeks ago, 5 months ago, 2 months ago, 1 month ago etc etc and I can't figure out why.

但是,如果我只运行:git log --before = 4 month --pretty = format:%ci,%cr,可以按预期工作。

But if I only run: git log --before="4 month" --pretty=format:"%ci, %cr, " It works as intended.

有人可以给我任何指导吗?

Can anyone give me any guidance?

推荐答案

git日志中的 -1 -1 [过滤器] $ k 将:

The -1 in git log -1 [filters] $k will :


  • 展开 git log的历史记录[过滤器] $ k

  • 将此历史记录限制为第一行

因此,如果分支的历史记录中有3个月的提交(我想:您的任何分支都有),则 git log -1 --before = 3 month $ k 始终显示1行,这是其历史上第一个提交超过3个月的行。

So if a branch has a 3 month old commit in its history (I would guess : any of your branches does), git log -1 --before="3 month" $k will always show 1 line -- the first commit in its history that is more than 3 month old.

您的前导 [...] 条件将始终为真。

Your leading if [ ... ] condition will always be true.

要解决此问题,您可以限制提交的范围以仅选择每个分支的最前面的提交:

To fix that, you can limit the range of commits to select only the leading commit of each branch :

git log --before="3month" $k^..$k

这篇关于git log --before =“ 4个月”向我显示3周前已提交的分支。我究竟做错了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆