gpt4 book ai didi

git - 特定git命令的颜色输出

转载 作者:行者123 更新时间:2023-12-02 21:27:47 25 4
gpt4 key购买 nike

我正在编写一个运行 git 命令并捕获输出的工具,并且我希望将输出着色。 Git 注意到该工具不是终端,因此需要将 color.ui 设置为 always。我真的不想在全局/存储库配置文件中设置它,因为它会与使用 git 的其他程序混淆。 git book也明确不鼓励这样做:

You’ll rarely want color.ui = always. In most scenarios, if you want color codes in your redirected output, you can instead pass a --color flag to the Git command to force it to use color codes. The color.ui = true setting is almost always what you’ll want to use.

遗憾的是,并非所有 git 命令都支持 --color 标志,尤其是 git statusgit pull

那么,如何强制一个 git 命令使用颜色呢?是否有我可以设置的配置变量,例如自定义 git 配置文件?

最佳答案

您可以使用-c option覆盖配置值。这适用于所有 git 命令。例如:

git -c color.ui=always status > status_file

将颜色代码输出到文件中。它看不到 pty,因此不会尝试分页。

关于git - 特定git命令的颜色输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23107594/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com