Git:无法重定向/解析'git fetch --dry-run'命令的输出

San*_*raj 4 git bash shell io-redirection

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

注意:我正在使用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]$ 
Run Code Online (Sandbox Code Playgroud)

我正在尝试解析git fetch --dry-run命令的输出以检查local(master)分支是否与remote(origin/master)分支是最新的.

Dan*_*tch 9

一些git的状态输出转到STDERR.如果你想要通过它,请将STDERR合并到STDOUT,如下所示:

git fetch --dry-run 2>&1 | grep ssh
Run Code Online (Sandbox Code Playgroud)