【问题标题】:How to list branches in git with the number of commits ahead or behind master?如何列出 git 中的分支以及 master 之前或之后的提交数?
【发布时间】:2021-03-04 08:37:05
【问题描述】:

我真的很喜欢 Github /branches 页面如何列出分支和一列,该列指示分支在 master 之前或之后提交的数量。

有没有办法在控制台/cli 中查看这些信息?

编辑:This solution 展示了如何让单个分支的提交提前/落后。但是我怎么能为所有本地分支机构做到这一点呢?

【问题讨论】:

  • 这能回答你的问题吗? git ahead/behind info between master and branch?
  • @flaxel 之类的,适用于单个分支,但我如何列出所有分支的提交数在前面/后面?
  • 您可以fetch all branches然后获取每个分支的信息。
  • @flaxel 是的,但我不想为每个分支键入命令。我想发出一个命令,列出所有具有提交偏移量的分支。

标签: git github


【解决方案1】:
git for-each-ref refs/heads/ --format='%(refname:short)' |
while read branch; do
    echo -n "$branch: "
    git rev-list --left-right --count master..$branch
done

文档:

https://git-scm.com/docs/git-for-each-ref

https://git-scm.com/docs/git-rev-list

【讨论】:

  • 你能帮我把它变成一个 git 别名吗?我试过list = ! git for-each-ref refs/heads/ --format='%(refname:short)' | while read branch; do; echo -n "$branch: "; git rev-list --left-right --count master..$branch; done 但我得到这个错误$ git list git for-each-ref refs/heads/ --format='%(refname:short)' | while read branch: -c: line 1: syntax error: unexpected end of file
  • 我认为由于代码量和复杂性,最好写一个 shell 脚本,而不是 git 别名。
猜你喜欢
  • 2022-11-10
  • 2019-12-15
  • 2020-11-05
  • 2012-07-26
  • 1970-01-01
  • 1970-01-01
  • 2020-05-07
相关资源
最近更新 更多