Can git operate in “silent mode”?

前端 未结 4 1582
借酒劲吻你
借酒劲吻你 2020-12-01 11:45

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 sup

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-01 12:06

    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 "$@" $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.

提交回复
热议问题