用于多个远程设备的git分支

用于多个远程设备的git分支,git,git-branch,gawk,git-remote,Git,Git Branch,Gawk,Git Remote,运行git branch-r时,我会看到远程存储库中的分支。 有没有办法在同一工作目录中查看多个存储库的分支? 我的目标是创建一个文件,列出两个存储库中的所有分支,如下所示: repo1:master,dev,qa,fy-2473 repo2:master,dev,fy-1128,staging repo3:master,fy-1272,staging 诸如此类。 我用这个来正确打印分支: git branch -r | awk -F' +|/' -v ORS=, '{if($3!="HEAD

运行
git branch-r
时,我会看到远程存储库中的分支。 有没有办法在同一工作目录中查看多个存储库的分支? 我的目标是创建一个文件,列出两个存储库中的所有分支,如下所示:

repo1:master,dev,qa,fy-2473
repo2:master,dev,fy-1128,staging
repo3:master,fy-1272,staging
诸如此类。 我用这个来正确打印分支:

git branch -r | awk -F' +|/' -v ORS=, '{if($3!="HEAD") print $3}' >> repolist.txt
我只需要让这个功能与几个存储库协同工作,而不必为了这个单一目的克隆它们中的每一个。
谢谢。

您可以使用将存储库添加到同一工作目录,然后在执行
git branch-r
时,您将看到所有存储库

例如:

git remote add repo1 http://github.com/example/foo.git
git remote add repo2 http://bitbucket.com/example/bar.git
git fetch --all
git branch -r
将列出:

repo1/master
repo1/dev
repo2/master
repo2/featureXYZ

您可以使用将存储库添加到同一工作目录中,然后在执行
git branch-r
时将看到所有存储库

例如:

git remote add repo1 http://github.com/example/foo.git
git remote add repo2 http://bitbucket.com/example/bar.git
git fetch --all
git branch -r
将列出:

repo1/master
repo1/dev
repo2/master
repo2/featureXYZ

运行
git remote add
添加所有远程存储库,运行
git fetch
检索/更新远程存储库的信息后,
git branch-a
将显示所有远程和本地分支。对于远程分支,其格式如下所示:

remotes/{remote_name}/{branch_name}

运行
git remote add
添加所有远程存储库,运行
git fetch
检索/更新远程存储库的信息后,
git branch-a
将显示所有远程和本地分支。对于远程分支,其格式如下所示:

remotes/{remote_name}/{branch_name}

使用
git remote Add
将您的repo作为远程对象添加到您的本地repo,然后
git fetch--all
并调整您的awk命令以生成您想要的结果

此命令将生成您期望的输出

git branch -r | awk '
    # split remote and branch
    {
        remote = substr($1, 0, index($1, "/") - 1)
        branch = substr($1, index($1, "/") + 1)
    }

    # eliminate HEAD reference
    branch == "HEAD" { next }

    # new remote found
    remote != lastRemote {
        # output remote name
        printf "%s%s:", lastRemote ? "\n" : "", remote
        lastRemote = remote
        # do not output next comma
        firstBranch = 1
    }

    # output comma between branches
    !firstBranch { printf "," }
    firstBranch { firstBranch = 0 }

    # output branch name
    { printf branch }

    # final linebreak
    END { print "" }
'
或作为一行没有评论

git branch -r | awk '{ remote = substr($1, 0, index($1, "/") - 1); branch = substr($1, index($1, "/") + 1) } branch == "HEAD" { next } remote != lastRemote { printf "%s%s:", lastRemote ? "\n" : "", remote; lastRemote = remote; firstBranch = 1; } !firstBranch { printf "," } firstBranch { firstBranch = 0 } { printf branch } END { print "" }'

使用
git remote Add
将您的repo作为远程对象添加到您的本地repo,然后
git fetch--all
并调整您的awk命令以生成您想要的结果

此命令将生成您期望的输出

git branch -r | awk '
    # split remote and branch
    {
        remote = substr($1, 0, index($1, "/") - 1)
        branch = substr($1, index($1, "/") + 1)
    }

    # eliminate HEAD reference
    branch == "HEAD" { next }

    # new remote found
    remote != lastRemote {
        # output remote name
        printf "%s%s:", lastRemote ? "\n" : "", remote
        lastRemote = remote
        # do not output next comma
        firstBranch = 1
    }

    # output comma between branches
    !firstBranch { printf "," }
    firstBranch { firstBranch = 0 }

    # output branch name
    { printf branch }

    # final linebreak
    END { print "" }
'
或作为一行没有评论

git branch -r | awk '{ remote = substr($1, 0, index($1, "/") - 1); branch = substr($1, index($1, "/") + 1) } branch == "HEAD" { next } remote != lastRemote { printf "%s%s:", lastRemote ? "\n" : "", remote; lastRemote = remote; firstBranch = 1; } !firstBranch { printf "," } firstBranch { firstBranch = 0 } { printf branch } END { print "" }'

伟大的关于如何重新适应我的awk以实现我的最终结果,有什么建议吗?@Moshe:不幸的是,我对awk不是很流利。@Moshe接受我的回答,你已经掌握了你需要的所有信息。;-)伟大的关于如何重新适应我的awk以实现我的最终结果,有什么建议吗?@Moshe:不幸的是,我对awk不是很流利。@Moshe接受我的回答,你已经掌握了你需要的所有信息。;-)