git - 显示所有分支的 git 前后信息,包括远程

标签 git

在 github 项目上,您可以转到/branches 页面并设置像这样的漂亮图表,其中每个分支显示每个分支相对于 master 的落后程度和领先程度。

git branch ahead behind

有没有类似的命令行工具?也适用于 Remote 的东西?例如,

git branch -v -v

接近我要找的东西,但只适用于本地分支机构。

最佳答案

我也对此很好奇,所以我刚刚准备了一个 git branch-status使用 git for-each-ref

提供此信息的脚本
#!/bin/bash
# by http://github.com/jehiah
# this prints out some branch status (similar to the '... ahead' info you get from git status)
 
# example:
# $ git branch-status
# dns_check (ahead 1) | (behind 112) origin/master
# master (ahead 2) | (behind 0) origin/master
 
git for-each-ref --format="%(refname:short) %(upstream:short)" refs/heads | \
while read local remote
do
    [ -z "$remote" ] && continue
    git rev-list --left-right "${local}...${remote}" -- 2>/dev/null >/tmp/git_upstream_status_delta || continue
    LEFT_AHEAD=$(grep -c '^<' /tmp/git_upstream_status_delta)
    RIGHT_AHEAD=$(grep -c '^>' /tmp/git_upstream_status_delta)
    echo "$local (ahead $LEFT_AHEAD) | (behind $RIGHT_AHEAD) $remote"
done

用法:

$ git branch-status
dns_check (ahead 1) | (behind 112) origin/master
master (ahead 2) | (behind 0) origin/master

关于git - 显示所有分支的 git 前后信息,包括远程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7773939/

相关文章:

git - 命令确定当前 HEAD 的上游 ref?

git - 推送时使用的是本地版本的git还是远程版本的git?

eclipse - 提交项目不显示在 Eclipse 中提交对 Git 存储库的更改 pop 窗口

GIT 将分支克隆到另一个目录中的旧提交

git - Beyond Compare 2 作为 Git Mergetool

git - 获取 svn HEAD git 提交号?

git - 我可以/应该如何处理这个 git gc 错误? (rm : cannot unlink pack Permission denied)

GIT Diff 在许多文件上说 100644 → 100755

linux - 从 public_html_source 到 public_html 的符号链接(symbolic link)

git - 使用 Git 将远程 'origin' 更改为 'upstream'