2012-10-30 87 views
4

打印在控制檯上的git fetch命令的輸出消息的特別之處是什麼?我不能夠使用grepxargs等不能輸出重定向到一個文件也..Git:無法重定向/解析'git fetch --dry-run'命令的輸出

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

[[email protected] santest-code]$ 
[[email protected] santest-code]$ git fetch --dry-run > /tmp/1 
From ssh://git.code.sf.net/p/santest/code 
    9f068d0..2b9dc4e master  -> origin/master 
[[email protected] santest-code]$ 
[[email protected] santest-code]$ cat /tmp/1    <= no data 
[[email protected] santest-code]$ 
[[email protected] 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 
[[email protected] santest-code]$ 
[[email protected] santest-code]$ git --version 
git version 1.7.11.4 
[[email protected] santest-code]$ 

我試圖解析命令git fetch --dry-run的輸出檢查本地(master)分支是否與遠程分支(origin/master)保持同步。

回答

9

某些git的狀態輸出爲STDERR。如果你想通過它,將STDERR合併到STDOUT中,如下所示:

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