【问题标题】:Show branches that do not contain commit显示不包含提交的分支
【发布时间】:2012-05-22 17:55:57
【问题描述】:

git branch -a --contains <hash> 给了我所有包含hash 的分支。我想要的是git branch -a --no-contains <hash>。不幸的是,似乎没有命令可以完成此操作,所以我认为解决方案类似于:

git branch -a | grep -v output of(git branch -a --contains) 但我的 bash 无法胜任这项任务。

Show all branches that commit A is on and commit B is not on? 似乎适用,但该方法似乎比必要的复杂。

完成上述任务的最佳/最简单的方法是什么?

【问题讨论】:

  • 为了可见性:Git 2.13 中添加了--no-contains 标志.. 如my answer 中所述。

标签: git branch dvcs


【解决方案1】:

grep 有一个匹配固定字符串的-F 选项。对你正在做的事情很有用。

git branch -a | grep -vF "$(git branch -a --contains <hash>)"

不幸的是,-F 会过滤掉部分匹配的分支名称。正如 antak 所建议的,我们可以使用comm 来获得更可靠的差异。

git branch -a | sort | comm -3 - <(git branch -a --contains <hash> | sort)

【讨论】:

  • 请注意,这将错误地隐藏部分匹配包含所述提交的分支名称的分支。例如echo -e "aaa\nbbb" | grep -vF "$(echo aa)"
  • @antak 谢谢!好收获!
【解决方案2】:

--no-contains 标志已添加到 Git 2.13。

【讨论】:

    【解决方案3】:

    由于如果分支名称部分匹配,则接受的答案将发生冲突,因此这里有一个处理这种情况的答案。

    git branch -a | comm -3 - <(git branch -a --contains <hash>)
    

    如果comm: file 1 is not in sorted order 警告打扰您,则可以将| sort 添加到两个命令的末尾。但是,这不是获得正确结果所必需的,因为两个输入的顺序是等价的。

    【讨论】:

      猜你喜欢
      • 2017-08-11
      • 2020-03-20
      • 1970-01-01
      • 2011-05-30
      • 1970-01-01
      • 2022-01-01
      • 2021-11-06
      • 2020-05-22
      • 2013-04-24
      相关资源
      最近更新 更多