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

标签 git bash shell io-redirection

控制台打印的 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 的状态输出到 STDERR。如果你想 grep 通过它,像这样将 STDERR merge 到 STDOUT 中:

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

关于Git:无法重定向/解析 'git fetch --dry-run' 命令的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13146187/

相关文章:

Linux命令不是很清楚

git - 拒绝 git push

asp.net - GIT + HTTP 跨网络失败

mysql - Bash 从 96 个数据库导出不同的表

linux - 为什么在尝试使用 sed 命令删除字符串时出现此错误?

linux - 如何终止 shell 脚本中的 fork 进程?

git - 使用 BeyondCompare 查看 GIT 中文件之间的差异

linux - 生产服务器上的 NodeJS - 权限

arrays - bash中多维数组的长度

postgresql - 自动化数据库连接