git可以在“静音模式”下运行吗? [英] Can git operate in "silent mode"?

查看:84
本文介绍了git可以在“静音模式”下运行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在无声模式下执行任何git命令?例如,我可以说 git push origin 并且屏幕上没有显示任何内容吗?



我想我可以将IO重定向到 / dev / null (工作正常),但是.. git自然允许这样的事情吗?



<下面是一个快速脚本,它会自动执行EOD提交,当我需要赶上火车并且不想在我的本地计算机上留下代码时使用。

  1清除
2
3 cd
4 cd回购​​/活动
5
6给我$ * b $ b 7
8 cd $ i
9 echo推送$ i
10 git add。 -A>> / dev / null
11 git commit -a -mEOD自动提交>> / dev / null
12 git push origin>> / dev / null
13 echo
14 cd ..
15完成



重定向输出到/ dev / null似乎是对我的一种自然的方式。虽然我在过去定义了一个quiet_git shell函数,用于cron作业:

b stdout = $(tempfile)
stderr = $(tempfile)

if! git$ @< / dev / null> $ stdout 2> $ stderr;然后
cat $ stderr>& 2
rm -f $ stdout $ stderr
出口1
fi

rm -f $ stdout $ stderr
}

这会抑制stdout和stderr,除非git命令失败。它不漂亮;实际上stdout文件被忽略,它应该只是将其重定向到/ dev / null。虽然,工程。然后,您可以稍后在脚本中执行quiet_git push等操作。


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?

I suppose i can redirect IO to /dev/null (works fine), but .. does git allow something like this naturally?

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

  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.

解决方案

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:

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.

这篇关于git可以在“静音模式”下运行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆