美文网首页
repo工程批量检出Branch

repo工程批量检出Branch

作者: 小磊长江大 | 来源:发表于2018-07-05 17:40 被阅读0次

我司在安卓开发中使用一个确定的branch name去跟踪某个确切bug,因此在一个repo工程中下面的所有git 工程都会提交到该bug分支,因此我们可以在repo工程根目录使用如下脚本将所有修改快速切到该分支:

#!/bin/bash
################################
#my company use a certain branch to track a certain bug
#so all releated changes can be checkout by a certain branch name
#just use this shell in your repo project to checkout these branches just one-time
###############################
BRANCH=$1
if [ 1 -gt $# ]; then
    echo "Usage "$0" branch_name"
    exit 1
fi

REPOS=$(repo forall -c pwd)
for path in $REPOS
do
        pushd $path > /dev/null
        RESULT=$(git branch -a|grep $BRANCH)
        if [ -n "$RESULT" ]; then
#          echo "find branch in "$path
          FILE=$(git status --porcelain|awk '/\ M/ { print $2; }')
          if [ -n "$FILE" ]; then
                git diff $FILE > $(date "+%Y%m%d").patch
                git stash -q
          fi
          git checkout -q $BRANCH
          CHECK_BRANCH=$(git branch | awk '/\*/ { print $2; }')
#          echo "branch after is "$CHECK_BRANCH
          if [ "$CHECK_BRANCH" != "$BRANCH" ]; then
                echo "failed to checkout branch in "$path", please check it !"
          exit
          fi
        fi
        popd > /dev/null
done
echo "checkout branch to releated git folder to "$BRANCH" success !"

相关文章

网友评论

      本文标题:repo工程批量检出Branch

      本文链接:https://www.haomeiwen.com/subject/nsopuftx.html