How can I get rid of the 'remote: ' messages that appear on every line returned by post-receive in git?
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 k开发者_如何学运维now it's possible because I've seen it in practice, I just don't know how it's done.)
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).
精彩评论