如何让git产生输出到文件?

der*_*ugo 3 command-line bash git output stdout

我想git clone使用

git clone https://github.com/someRepository > git_clone.file
Run Code Online (Sandbox Code Playgroud)

但相反,我在终端中显示/更新了输出,例如

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.
Run Code Online (Sandbox Code Playgroud)

但文件git_clone.file已生成但仍为空。

我最初的目标是绕过输出git到函数中(请参阅我的问题here)。但是现在我意识到git甚至似乎没有产生stdout真正但不知何故不同的输出,因为没有任何内容写入文件。

如何从中获取此显示的输出git以将其重定向到文件/函数?


编辑

建议的stderr(and 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
Run Code Online (Sandbox Code Playgroud)

都给了我相同的结果:只有这条线

Cloning to 'someRepository' ...
Run Code Online (Sandbox Code Playgroud)

出现在 git_clone.file


背景资料

为什么我需要这个?

正如我在这里的另一个问题中所解释的,总是在输出我的脚本的底部写了一个自定义进度条。(我在 multible 脚本中使用它但是)在这种情况下,脚本将很多(直到现在 107)git 存储库从 github 迁移到我们自己的 Gitlab-Server 并修复了 Git LFS 支持,如果没有它,通常会丢失。

所以我仍然希望看到 git 的所有输出,但也希望我的进度条在终端输出的底部工作。

der*_*ugo 8

谢谢你的帮助!


我刚刚找到了解决方案:

第1部分

(感谢甜点回答
gitby design 永远不会写信给stdoutbut stderr。所以我也需要重定向stderr,以便使用

git clone XYZ &> git_clone.file
Run Code Online (Sandbox Code Playgroud)

第2部分

无论如何,这还不够,我只收到文件输出的“无趣”部分,但没有收到我真正想要的进度行。

再次做进一步研究,man git-clone我意识到存在一个选择

git clone XYZ &> git_clone.file
Run Code Online (Sandbox Code Playgroud)

虽然我认为它实际上已经附加到终端上,但现在这似乎迫使 git 写出我最感兴趣的进度部分的行,最后stderr我也可以让他们使用

git clone --progress XYZ &> git_clone.file
Run Code Online (Sandbox Code Playgroud)