我怎样才能摆脱“远程:” git 中 post-receive 返回的每一行上出现的消息?
我在 git 中创建了一个 post-receive 挂钩。钩子将消息输出到屏幕,这些消息被发送回执行推送的 git 客户端,然后输出回来。
如何去掉每行输出之前的“remote:”文本?这是相当分散注意力的。 (我知道这是可能的,因为我在实践中见过它,我只是不知道它是如何完成的。)
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.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
注意:前缀对于避免将来自远程系统的消息误认为来自本地系统的消息很重要。
也就是说,没有办法关闭前缀,但它们都会写入 stderr。您可以重定向/捕获/过滤 git push 的 stderr 来执行您想要的操作。
一个粗略的做法可能是这样的:
它将 stdout 发送到管道并使 stderr 转到相同的位置。在管道的另一端,sed 读取组合输出并删除任何
remote:
前缀。这应该没问题,因为我们不太可能在 stdout 流中看到remote:
前缀。像这样组合 stdout 和 stderr 对于交互式使用来说通常是可以接受的(因为它们可能无论如何都会进入同一个 tty 设备),但对于在自动化上下文(例如脚本)中使用可能不是一个好主意。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:
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 seeremote:
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).