【问题标题】:Git: unable to redirect/parse the output of 'git fetch --dry-run' commandGit:无法重定向/解析“git fetch --dry-run”命令的输出
【发布时间】:2012-10-30 19:19:51
【问题描述】:

git fetch命令的输出信息在控制台打印有什么特别之处?我无法使用grepxargs 等。也无法将输出重定向到文件..

注意:我正在使用git fetch --dry-run 命令

[sangeeth@localhost santest-code]$ 
[sangeeth@localhost santest-code]$ git fetch --dry-run > /tmp/1
From ssh://git.code.sf.net/p/santest/code
   9f068d0..2b9dc4e  master     -> origin/master
[sangeeth@localhost santest-code]$ 
[sangeeth@localhost santest-code]$ cat /tmp/1              <= no data
[sangeeth@localhost santest-code]$  
[sangeeth@localhost santest-code]$ git fetch --dry-run | grep "ssh"     <= output has both lines
From ssh://git.code.sf.net/p/santest/code
   9f068d0..2b9dc4e  master     -> origin/master
[sangeeth@localhost santest-code]$ 
[sangeeth@localhost santest-code]$ git --version 
git version 1.7.11.4
[sangeeth@localhost santest-code]$ 

我正在尝试解析 git fetch --dry-run 命令的输出,以检查本地 (master) 分支是否与远程 (origin/master) 分支保持同步。

【问题讨论】:

    标签: git bash shell io-redirection


    【解决方案1】:

    git 的一些状态输出到STDERR。如果你想通过它 grep,像这样将 STDERR 合并到 STDOUT 中:

    git fetch --dry-run 2>&1 | grep ssh
    

    【讨论】:

      猜你喜欢
      • 2013-06-17
      • 2016-10-12
      • 2013-01-21
      • 2010-10-04
      • 2020-11-26
      • 2014-02-06
      • 1970-01-01
      • 2014-12-11
      相关资源
      最近更新 更多