How can I get rid of the 'remote: ' messages that appear on every line returned by post-receive in git?

StackOverflow https://stackoverflow.com/questions/3170337

  •  02-10-2019
  •  | 
  •  

Pergunta

I've created a post-receive hook in git. The hook output messages to the screen, which are sent back to the git client doing the push, and outputted back.

How can I get rid of the 'remote: ' text before every single line of output? It's rather distracting. (I know it's possible because I've seen it in practice, I just don't know how it's done.)

Foi útil?

Solução

Note: The prefix can be important to avoid mistaking messages from the remote system as messages from the local system.

That said, there is no way to turn off the prefix, but they are all written to stderr. You could redirect/capture/filter the stderr of git push to do what you want.

A rough way of doing might be something like this:

git push ... 2>&1 | sed -e 's/^remote: //'

It sends stdout to a pipe and makes stderr goto the same place. At the other end of the pipe, sed reads the combined output and deletes any remote: prefixes. This should be okay since it we are unlikely to see remote: prefixes in the stdout stream. Combining stdout and stderr like this is generally acceptable for interactive use (since they were probably going to the same tty device anyway), but it may not be a good idea for use in automated contexts (e.g scripts).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top