Trying to redirect 'git gc' output

丶灬走出姿态 提交于 2019-12-01 17:26:56

You can try this:

script -q -c 'git gc' > log

Or this (with more readable output):

script -q -c 'git gc' | sed 's/\r.*//g' > log

Keith Thompson

It doesn't use ncurses (programs that use ncurses typically take over the entire screen).

Running

strace -p -o git-gc.strace git gc

shows that the progress messages are written to stderr (file descriptor 2) -- but they're disabled if stderr is not a tty. So if you run

git gc 2>some_file

then some_file will be empty, because git gc doesn't produce the progress messages at all.

Looking at the source code (builtin/gc.c), there's a quiet option that's set by the --quiet command-line option:

git gc --quiet

I haven't found the code that turns quiet on if stderr is not a tty, but I see similar code elsewhere in the git sources, such as:

quiet = !isatty(2);

There is no command-line option to turn the quiet option off.

Which means that if you want to capture the progress output of git gc, you'll need to convince it that it's running with stderr directed to a tty.

some guy's answer provides one way to do that.

But since the code goes out of its way to produce the progress messages only if it's writing to a terminal, you might consider whether you really need to capture those messages. They're not designed to be saved, and they might not be all that useful.

If you want to examine the git sources yourself (and, if you're sufficiently motivated, hack them to force the progress messages to be written):

git clone git://git.kernel.org/pub/scm/git/git.git
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!