在 github 项目上,您可以转到/branches 页面并设置像这样的漂亮图表,其中每个分支显示每个分支相对于 master 的落后程度和领先程度。
有没有类似的命令行工具?也适用于 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/