Bash 分解和解释git分支的结果-rvv

Bash 分解和解释git分支的结果-rvv,bash,git,version-control,Bash,Git,Version Control,我使用哪些特定命令来分解以下git分支命令返回的列 git branch -rvv | grep "Merge pull request" | grep "$fromCurrentRepoTo" 此外,除了简单地给出只返回单个列的值的命令外,结果中的每列是什么 当给出-vv标志时,结果将: 显示每个头部的sha1和提交主题行,以及与上游分支的关系(如果有),以及上游分支的名称 这意味着结果中将包括以下4列: sha1 commit subject line relationship to

我使用哪些特定命令来分解以下
git分支
命令返回的列

git branch -rvv  | grep "Merge pull request" | grep "$fromCurrentRepoTo"
此外,除了简单地给出只返回单个列的值的命令外,结果中的每列是什么

当给出
-vv
标志时,结果将:

显示每个头部的sha1和提交主题行,以及与上游分支的关系(如果有),以及上游分支的名称

这意味着结果中将包括以下4列:

sha1 
commit subject line
relationship to upstream branch (if any)
name of the upstream branch
但是下面的结果似乎包括6列,而不仅仅是上面列出的4列

为了帮助分解这个由两部分组成的操作的答案,我包含了完整的命令列表和完整的终端输出

全本 作为参考,上述命令之前的完整命令序列如下:

echo "About to currentRepo=$(git rev-parse --abbrev-ref HEAD)"
currentRepo=$(git rev-parse --abbrev-ref HEAD)
echo "about to echo currentRepo"
echo $currentRepo
fromVar="from "
toVar=" to"
fromCurrentRepoTo="$fromVar$currentRepo$toVar"
echo "about to echo fromCurrentRepoTo"
echo $fromCurrentRepoTo
echo "About to git branch -rvv  | grep 'Merge pull request' | grep fromCurrentRepoTo"
git branch -rvv  | grep "Merge pull request" | grep "$fromCurrentRepoTo"
echo "----------------------------------"  
echo "About to git branch -rvv"
git branch -rvv
终端输出 当运行上述命令时,以下命令将输出到控制台:

build   03-Apr-2018 11:08:52    About to currentRepo=Issue_Example
build   03-Apr-2018 11:08:52    about to echo currentRepo
build   03-Apr-2018 11:08:52    Issue_Example
build   03-Apr-2018 11:08:52    about to echo fromCurrentRepoTo
build   03-Apr-2018 11:08:52    from Issue_Example to
build   03-Apr-2018 11:08:52    About to git branch -rvv  | grep 'Merge pull request' | grep fromCurrentRepoTo
build   03-Apr-2018 11:08:52      origin/feature/Feature_Version_Example 37d71e5 Merge pull request #2 in PCFPT/scriptsforexamples from Issue_Example to feature/Feature_Version_Example
build   03-Apr-2018 12:56:04    ----------------------------------
build   03-Apr-2018 12:56:04    About to git branch -rvv
build   03-Apr-2018 12:56:04      origin/HEAD                            -> origin/master
build   03-Apr-2018 12:56:04      origin/Issue_Example                   6f8346a who is the dirty rat now?
build   03-Apr-2018 12:56:04      origin/feature/Feature_Version_Example 37d71e5 Merge pull request #2 in PCFPT/scriptsforexamples from Issue_Example to feature/Feature_Version_Example
build   03-Apr-2018 12:56:04      origin/master                          cf60eb7 Initial Commit
build   03-Apr-2018 12:56:04    ----------------------------------
重申问题 问题的两部分可重新表述如下,包括上述终端输出中返回的实际数据:

  • 每一列是什么?(猜测在下面的括号中)
  • 为了将每列的值提取到一个单独的变量中,我需要什么特定的语法

  • 原点/特征/特征\u版本\u示例
  • 37d71e5(最近提交的sha1)
  • 合并拉取请求#2(提交的主题行?)
  • PCFPT/scriptsforexamples(远程项目和存储库)
  • 问题(举例)
  • 功能/功能\u版本\u示例

  • 我之所以包含
    bash
    标记,是因为它位于CentOS服务器上,上面显示了一些
    bash
    命令。
    git branch-vv
    git branch-rvv
    (等于
    git branch-vv-r
    )的输出是不同的

    • 对于
      git branch-vv
      ,它将返回与您提到的类似的四列(基于本地分支的列表):

    • 对于
      git分支-rvv
      ,它将返回三列(基于跟踪分支的列表):

    因此,您使用的命令
    git branch-rvv | grep“Merge pull request”| grep“$fromCurrentRepoTo”
    包含三列返回,如下所示:

    Column 1: origin/feature/Feature_Version_Example
    Column 2: 37d71e5
    Column 3: Merge pull request #2 in PCFPT/scriptsforexamples from Issue_Example to feature/Feature_Version_Example
    
    要获取跟踪分支名称(第1列)或sha-1值(第2列),可以按空格分割输出字符串(提交消息不可用,因为提交消息中通常有空格):

    要从提交中获取提交消息(第3列),可以使用以下命令:

    git show -s --format=%s <sha-1 value>
    
    git show-s--格式=%s
    
    非常感谢您和+1的高质量回答。我希望当我回到激发这项调查的项目的那一部分时,能更仔细地研究它。我没有将其标记为已接受的原因是,为了集成您的建议,我必须将每个列转换为一个可用的变量。我希望用一段代码来解决这个问题,使我能够单独打印每一列,就像我有
    object1.property1
    object1.property2
    ,和
    object1.property3
    ,等等一样。我可以很容易地做到这一点,但我想在我将其标记为已接受之前完成它。当然,你可以在完成作业后标出答案。如果您在查询过程中遇到其他问题,请随时告诉我:)您好!我注意到你喜欢在你的文章中使用引号块设备。我同意这是方便的,但它实际上不是一个通用的荧光灯。它的用途反映了HTML中的
    ——它用于引用,即在书面资源中或某人所说的话。它有助于区分你的帖子中哪些内容是你自己的声音,哪些内容是别人的声音。如果你能以这种方式使用引用块,那就太好了,因为这将节省志愿者编辑的一些工作。谢谢
    Column 1: origin/feature/Feature_Version_Example
    Column 2: 37d71e5
    Column 3: Merge pull request #2 in PCFPT/scriptsforexamples from Issue_Example to feature/Feature_Version_Example
    
    st=$(git branch -rvv |grep "Merge pull request" | grep "$fromCurrentRepoTo")
    IFS=' '
    for t in $st; do
      echo $t
    done
    
    git show -s --format=%s <sha-1 value>