问题
我想将git clone
的输出写入文件,使用
git clone https://github.com/someRepository > git_clone.file
输出如下
Cloning to 'someRepository' ...
remote: Counting objects: 2618, done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 2618 (delta 2), reused 12 (delta 1), pack-reused 2603
Received objects: 100% (2618/2618), 258.95 MiB | 4.39 MiB/s, Done.
Resolving Differences auf: 100% (1058/1058), Done.
Check Connectivity ... Done.
件git_clone.file
可以生成,但仍然为空。
重定向stderr
(和stdout
)没有解决问题。
git clone https://github.com/someRepository 2> git_clone.file
git clone https://github.com/someRepository &> git_clone.file
git clone https://github.com/someRepository > git_clone.file > 2>&1
都给我同样的结果:
Cloning to 'someRepository' ...
答案1
我刚刚找到了解决方案:
第1部分
git
不会写入stdout
,但stderr
。需要重定向stderr
,以便使用
git clone XYZ &> git_clone.file
第2部分
再次执行man git-clone
--progress
progress status is reported on the standard error stream by
default when it is attached to a terminal, unless -q is
specified. This flag forces progress status even if the standard
error stream is not directed to a terminal.
git clone --progress XYZ &> git_clone.file
答案2
git clone
对输出使用stderr
,因此只需将它写入文件:
git clone https://github.com/someRepository 2>git_clone.file
或者,可以同时重定向stdout
和stderr
,通过这种方式,你可以确保命令生成的每个输出都被重定向:
git clone https://github.com/someRepository &>git_clone.file
git clone https://github.com/someRepository | cat
相关文章