gpt4 book ai didi

git - 我应该解析 git status 还是使用 gitsharp?

转载 作者:太空狗 更新时间:2023-10-29 13:16:22 25 4
gpt4 key购买 nike

我想将 git 集成到生产管道中以暂存 3dsmax 文件。虽然可以通过 TortoiseGit 使用 git,但我想从 Maxscript 与其通信以将自定义菜单命令添加到 3dsmax。

我应该解析 git status 输出文本来确定文件夹状态,还是应该使用一些包装工具来正确地与 git 通信?

我在考虑 gitsharp,因为它很容易从 Maxscript 调用 dotNet 对象,但我没有使用外部 dotNet 程序。

最佳答案

从 git 版本 1.7.0 开始,git status 有了一个 --porcelain 选项。的输出:

git status --porcelain

... 专为脚本使用而设计 - 输出的紧凑表示,其格式将在各个版本中保持一致。正如手册页所说:

Porcelain Format

The porcelain format is similar to the short format, but is guaranteed not to change in a backwards-incompatible way between git versions or based on user configuration. This makes it ideal for parsing by scripts. The description of the short format above also describes the porcelain format, with a few exceptions:

  1. The user’s color.status configuration is not respected; color will always be off.
  2. The user’s status.relativePaths configuration is not respected; paths shown will always be relative to the repository root.

There is also an alternate -z format recommended for machine parsing. In that format, the status field is the same, but some other things change. First, the -> is omitted from rename entries and the field order is reversed (e.g from -> to becomes to from). Second, a NUL (ASCII 0) follows each filename, replacing space as a field separator and the terminating newline (but a space still separates the status field from the first filename). Third, filenames containing special characters are not specially formatted; no quoting or backslash-escaping is performed.

因此,如上所述,您可能还需要考虑使用:

git status -z

...以获得更强大的输出格式。

关于git - 我应该解析 git status 还是使用 gitsharp?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1979609/

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