bash Silence git(无错误,无输出,不说话)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30378915/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 13:01:37  来源:igfitidea点击:

Silence git (no errors, no output, don't say a word)

gitbashsilent

提问by offthegrass

I'm using git to manage some custom packages. If the package is not in the first repo, I want to run a second command that tries another source. I don't need to tell the user that this is happening. The user doesn't need to know git exists.

我正在使用 git 来管理一些自定义包。如果该包不在第一个 repo 中,我想运行第二个命令来尝试另一个源。我不需要告诉用户这正在发生。用户不需要知道 git 的存在。

if ! git clone [email protected]:username/repo directory -q
        then
            #do something else
        fi

git still prints a fatal error in the console even with -q.

即使使用 .git 仍然在控制台中打印致命错误-q

So, how do I silence the little git?

那么,我如何让小混蛋保持沉默?

回答by Paul

Two ways:

两种方式:

git clone [email protected]:username/repo directory > /dev/null 2>&1- older bash

git clone [email protected]:username/repo directory > /dev/null 2>&1- 较旧的bash

and:

和:

git clone [email protected]:username/repo directory &> /dev/null- newer bash (Above version 4 according to the link below)

git clone [email protected]:username/repo directory &> /dev/null- 较新的 bash(根据以下链接高于版本 4)

For more details read about I/O Redirection in Bash. Essentially what you're doing here is redirect both stdoutand stderrto /dev/null, which is "nowhere".

有关更多详细信息,请阅读Bash 中的 I/O 重定向。本质上,您在这里所做的是将stdout和都重定向stderr/dev/null,这是“无处可去”。

回答by Harikrishna

git clone [email protected]:username/repo directory > /dev/null 2>&1 - older bash

git clone [email protected]:username/repo directory > /dev/null 2>&1 - 较旧的 bash

Above will be more compatible,

以上会更兼容,