找出哪些本地分支与远程不同步 [英] Find out which local branches are out of sync with remote
本文介绍了找出哪些本地分支与远程不同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个带有几个分支的git存储库.我怀疑某些分支没有被推到上游或已过时,或两者都没有(即分叉).
Suppose I have a git repository with several branches. I suspect some of the branches were not pushed upstream, or are outdated, or both (i.e. diverged).
是否有一种方法可以通过一个命令找出哪些分支与远程控制器不同步? (写脚本可以,但是我想知道是否已经有这样的脚本了.)
Is there a way to find out which branches are out of sync with remote with one command? (Writing a script is OK but I'd like to know if there's already such a script).
推荐答案
我已经完成了一个脚本.结果git branch -v
给出了必要的信息.
I've done a script. Turns out git branch -v
gives the necessary info.
〜/bin/git-total.sh:
~/bin/git-total.sh:
#!/bin/sh
for DIR in "$@"; do
# Only git dirs interesting
[ -d "$DIR/.git" ] && cd "$DIR" || continue
# git branch -v gives ahead/behind info
# using perl - sorry for this
MOD=`git branch -v | perl -wlne '/^..(\S+)\s+([a-f0-9]+)\s+(\[ahead\s+(\d+)\])/ or next; print "# Branch ahead: $1"; '`;
# a series of UGLY HACKs to get pretty-printing
[ ! -z "$MOD" ] && MOD="
$MOD"
git status | grep -q '^# Changes' && MOD="$MOD
# Uncommitted changes present"
# print summary
[ ! -z "$MOD" ] && echo -e "$DIR:$MOD"
cd -
done
这篇关于找出哪些本地分支与远程不同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文