www.cnblogs.com/ruiyqinrui

开源、架构、Linux C/C++/python AI BI 运维开发自动化运维。 春风桃李花 秋雨梧桐叶。“力尽不知热 但惜夏日长”。夏不惜,秋不获。@ruiY--秦瑞

python爬虫,C编程,嵌入式开发.hadoop大数据,桉树,onenebula云计算架构.linux运维及驱动开发.

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

当我运行的git克隆像往常一样,我看到:如何将`git clone`的完整输出重定向到一个文件?

$ git clone https://github.com/bensmithett/webpack-css-example 
Cloning into 'webpack-css-example'... 
remote: Counting objects: 179, done. 
remote: Total 179 (delta 0), reused 0 (delta 0), pack-reused 179 
Receiving objects: 100% (179/179), 24.07 KiB | 0 bytes/s, done. 
Resolving deltas: 100% (79/79), done. 
Checking connectivity... done 

然而,当我试图将其重定向到一个文件,我只看到这一点:

Cloning into 'webpack-css-example'... 

这里是我的尝试:

$ git clone https://github.com/bensmithett/webpack-css-example 2>&1 | tee out.log 
$ cat out.log 
Cloning into 'sample-data'... 

我在Node.js的试了一下为好,它做同样的事情:

const fs = require('fs'); 
const child = spawn('git clone https://github.com/bensmithett/webpack-css-example'); 
child.stdout.on('data', function(data){ 
    console.log(String(data)); 
}); 
child.stderr.on('data', function(data){ 
    console.log(String(data)); 
}); 
// Cloning into 'webpack-css-example'... 

为什么所有的remote:等东西没有通过管道连接到stdin/stderr?有什么方法可以捕获输出吗?如果没有,发生了什么事情使得输出显示在终端中,但它没有通过stdout或stderr传递?

回答

6

默认情况下,仅当标准错误流指向终端时,Git才会显示克隆进度。由于您将其重定向到管道,输出流不再连接到终端。因此,为了捕获输出,您需要添加--progress参数来强制执行进度状态,例如,

git clone --progress https://github.com/foo/bar 2> out.log 

参见:man git-clone

--progress

进展状态被默认报告了标准错误流,当它被连接到末端,除非指定-q。即使标准错误流未定向到终端,此标志也会强制进度状态。

posted on 2022-01-27 11:09  秦瑞It行程实录  阅读(233)  评论(0编辑  收藏  举报
www.cnblogs.com/ruiyqinrui