git 可以在“静默模式”下运行吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8943693/
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
Can git operate in "silent mode"?
提问by James Raitsev
Is it possible to execute any git command in "silent" mode? For instance, can i say "git push origin
" and see nothing displayed on the screen?
是否可以在“静默”模式下执行任何 git 命令?例如,我可以说“ git push origin
”,然后在屏幕上看不到任何内容吗?
I suppose i can redirect IO to /dev/null
(works fine), but .. does git allow something like this naturally?
我想我可以将 IO 重定向到/dev/null
(工作正常),但是 .. git 是否自然地允许这样的事情?
Below is a quick script that does automatic EOD commit, used when i need to catch the train and don't want to leave code on my local computer
下面是一个自动执行 EOD 提交的快速脚本,当我需要赶火车并且不想在我的本地计算机上留下代码时使用
1 clear
2
3 cd
4 cd repo/active
5
6 for i in *
7 do
8 cd $i
9 echo "Pushing " $i
10 git add . -A >> /dev/null
11 git commit -a -m "EOD automatic commit" >> /dev/null
12 git push origin >> /dev/null
13 echo
14 cd ..
15 done
Please let me know.
请告诉我。
采纳答案by araqnid
Redirecting output to /dev/null seems like a natural way of doing it to me. Although I have in the past defined a quiet_git shell function like this for use in cron jobs:
将输出重定向到 /dev/null 对我来说似乎是一种自然的方式。虽然我过去定义了一个像这样的 quiet_git shell 函数用于 cron 作业:
quiet_git() {
stdout=$(tempfile)
stderr=$(tempfile)
if ! git "$@" </dev/null >$stdout 2>$stderr; then
cat $stderr >&2
rm -f $stdout $stderr
exit 1
fi
rm -f $stdout $stderr
}
This will suppress stdout and stderr, unless the git command fails. It's not pretty; in fact the stdout file is ignored and it should just redirect that to /dev/null. Works, though. And then you can just do "quiet_git push" etc. later on in the script.
这将抑制 stdout 和 stderr,除非 git 命令失败。它不漂亮;事实上,stdout 文件被忽略,它应该只是将它重定向到/dev/null。作品,虽然。然后您可以稍后在脚本中执行“quiet_git push”等操作。
回答by Thomas Edwards
You can use --quiet
or -q
, which can also be used for other Git commands:
您可以使用--quiet
或-q
,它也可以用于其他 Git 命令:
git commit --quiet
git push --quiet
回答by Hans Kristian
Using &> /dev/null
at the end gives you a completely silent git command output.
最后使用&> /dev/null
为您提供了一个完全无声的 git 命令输出。
git fetch origin master &> /dev/null
回答by VonC
Note that even with--quiet
, a git fetch
(which triggers a git gc
) would generate some output.
That is because of the git gc
part of the git fetch
.
请注意,即使使用--quiet
, a git fetch
(触发 a git gc
)也会产生一些输出。
这是因为中git gc
的一部分git fetch
。
Not anymore, starting git 2.1.1 (Sept 2014): see commit 6fceed3bea59d747c160972c67663e8b8c281229from Nguy?n Thái Ng?c Duy (pclouds
)
现在不一样了,开始git的2.1.1(9月2014):看提交6fceed3bea59d747c160972c67663e8b8c281229从 Nguyň泰伍Ç维战(? pclouds
)
fetch: silence git-gc
if --quiet
is given
获取:git-gc
如果--quiet
给出沉默
argv_array_pushl(&argv_gc_auto, "gc", "--auto", NULL);
if (verbosity < 0)
argv_array_push(&argv_gc_auto, "--quiet");
run_command_v_opt(argv_gc_auto.argv, RUN_GIT_CMD);