显示所有分支的git前进和后退信息,包括遥控器 [英] Show git ahead and behind info for all branches, including remotes

查看:172
本文介绍了显示所有分支的git前进和后退信息,包括遥控器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在github项目中,您可以访问/ branches页面,并选择像这样的漂亮图形,即每个分支显示多远落后以及每个分支与主控制器相距多远。





<有没有一种类似的命令行工具?与遥控器配合使用的东西?例如,

  git分支-v -v 

接近我在寻找的内容,但只适用于本地分行。

解决方案

我也很好奇这件事,所以我刚刚掀起了一个 git分支-status 脚本,该脚本使用 git for-each-ref



#!/ bin / bash
#by http://github.com/jehiah
#打印出一些分支状态(类似于您从git状态获得的'... ahead'信息)

#示例:
#$ git branch-status
#dns_check(ahead 1)| (在112之后)origin / master
#master(提前2)| (在0之后)origin / master

git for-each-ref --format =%(refname:short)%(upstream:short)refs / heads | \
,而读本地远程

[-z$ remote]&&继续
git rev-list --left-right $ {local} ... $ {remote} - 2> / dev / null> / tmp / git_upstream_status_delta ||继续
LEFT_AHEAD = $(grep -c'^<'/ tmp / git_upstream_status_delta)
RIGHT_AHEAD = $(grep -c'^>'/ tmp / git_upstream_status_delta)
echo$本地(前$ LEFT_AHEAD)|($ RIGHT_AHEAD后)$ remote

code $ $ $ :

  $ git branch-status 
dns_check(ahead 1)| (在112之后)origin / master
master(提前2)| (在0之后)origin / master


On a github project you can go to a /branches page and se pretty graphs like this one that for each branch show how far behind and how far ahead each branch is with respect to master.

Is there a command line tool that does something similar? Something that works with remotes as well? For example,

git branch -v -v

is close to what I am looking for, but only works for local branches.

解决方案

I've been curious about this as well, so i just whipped up a git branch-status script that gives this information using 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

Usage:

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

这篇关于显示所有分支的git前进和后退信息,包括遥控器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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