Git status over all repo's

后端 未结 4 982
隐瞒了意图╮
隐瞒了意图╮ 2020-12-06 07:17

What tools, if any, are available to show the status of my git repo\'s and how much they are forward/behind versus their remotes? I\'m imagining something like this exists:<

4条回答
  •  攒了一身酷
    2020-12-06 07:54

    You can find several scripts, all based on looking for .git folder:

    • git-multi-status.sh
    • find-dirty.sh
    • GitStatus (python)
    • Other options, as suggested in "Git Status Across Multiple Repositories on a Mac"
    • ...

    The first one can be adapted to display the kind of status you are after:

    #!/bin/bash
    
    # usage: $0 source_dir [source_dir] ...
    # where source_dir args are directories containing git repositories
    
    red="\033[00;31m"
    green="\033[00;32m"
    yellow="\033[00;33m"
    blue="\033[00;34m"
    purple="\033[00;35m"
    cyan="\033[00;36m"
    
    reset="\033[00m"
    
    
    if [ $# -eq 0 ] ; then
      ARGS=( "foldername" "foldername/subfoldername" )
    else
      ARGS=$@
    fi
    
    for i in ${ARGS[@]} ; do
      for gitdir in `find $i -name .git` ; do
        ( working=$(dirname $gitdir)
          cd $working
          RES=$(git status | grep -E '^# (Changes|Untracked|Your branch)')
          STAT=""
          grep -e 'Untracked' <<<${RES} >/dev/null 2>&1
          if [ $? -eq 0 ] ; then
            STAT=" $red[Untracked]$reset"
          fi
          grep -e 'Changes not staged for commit' <<<${RES} >/dev/null 2>&1
          if [ $? -eq 0 ] ; then
            STAT="$STAT $red[Modified]$reset"
          fi
          grep -e 'Changes to be committed' <<<${RES} >/dev/null 2>&1
          if [ $? -eq 0 ] ; then
            STAT="$STAT $green[Staged]$reset"
          fi
          grep -e 'Your branch is ahead' <<<${RES} >/dev/null 2>&1
          if [ $? -eq 0 ] ; then
            STAT="$STAT $yellow[Unpushed]$reset"
          fi
          grep -e 'Your branch is behind' <<<${RES} >/dev/null 2>&1
          if [ $? -eq 0 ] ; then
            STAT="$STAT $cyan[Unmerged]$reset"
          fi
    
          if [ -n "$STAT" ] ; then
            echo -e "$working :$STAT"
          fi
        )
      done
    done
    

提交回复
热议问题