让 git 显示特定文件名它是 运行 内容过滤器
Getting git to show specific filenames it is running content filters on
我正在调试已配置的 git 内容过滤器 (nbstripout
) 的工作,我正试图让 GIT_TRACE
向我显示它正在运行的文件,但是它没有。考虑:
$ GIT_TRACE=1 git pull origin master
[...] removed irrelevant sections of the output
16:49:28.846707 run-command.c:640 trace: run_command: git merge FETCH_HEAD
16:49:28.849309 git.c:344 trace: built-in: git merge FETCH_HEAD
Updating 1ea49ad..ae0ba93
16:49:28.863291 run-command.c:640 trace: run_command: nbstripout
16:49:28.864700 run-command.c:640 trace: run_command: nbstripout
16:49:28.866060 run-command.c:640 trace: run_command: nbstripout
[...] many more of the same
如何让 GIT_TRACE
的 run_command
显示传递给过滤器的参数?我在 git 的手册中查看了各种其他调试环境变量,但我没有看到任何可以启用该级别调试的内容。
我知道 git check-attr
,但我想查看 运行 时间跟踪,其中 运行 过滤了哪些文件以及哪些参数。
git 版本 2.17.1
我在 git 邮件列表和 Jeff King provided a workaround as an answer 上发布了这个问题。在 Jeff 的许可下,我在这里分享他的回答:
GIT_TRACE 应始终显示参数。但除非你指定
clean/smudge 过滤器配置中的参数,那么 Git 将不会通过任何参数。
stdin/stdout 流才是最重要的。
例如:
$ echo '* filter=foo' >.gitattributes
$ git config filter.foo.clean 'myfilter'
$ GIT_TRACE=1 git add .
19:42:16.516401 [pid=14112] git.c:415 trace: built-in: git add .
19:42:16.517454 [pid=14112] run-command.c:637 trace: run_command: myfilter
$ git config filter.foo.clean 'myfilter --foo'
$ touch .gitattributes ;# make sure we actually read it again ;)
$ GIT_TRACE=1 git add .
19:42:58.122942 [pid=14156] git.c:415 trace: built-in: git add .
19:42:58.124023 [pid=14156] run-command.c:637 trace: run_command: 'myfilter \
--foo'
您可以使用“%f”来传递文件名,例如:
$ git config filter.foo.clean 'myfilter %f'
$ touch .gitattributes
$ GIT_TRACE=1 git add .
19:44:51.187177 [pid=14318] git.c:415 trace: built-in: git add .
19:44:51.188256 [pid=14318] run-command.c:637 trace: run_command: 'myfilter \
'\''.gitattributes'\'''
当然,如果您的过滤器确实尊重
争论。对于可能没问题的 "clean" 过滤器(例如,如果它只是告诉
你的过滤器从文件系统而不是标准输入中读取),但它是
几乎肯定不是您想要的 "smudge" 过滤器。
您可以使用一些 shell 技巧来解决它:
git config filter.foo.clean 'f() { echo >&2 "cleaning "; myfilter ...; }; f %f'
然后即使没有 GIT_TRACE,您也会得到:
$ git add .
cleaning .gitattributes
或者,如果您真的只想为 GIT_TRACE 触发,请尝试以下操作:
$ git config filter.foo.clean 'f() { myfilter; }; f %f'
19:52:52.874064 [pid=14719] git.c:415 trace: built-in: git add .
19:52:52.875115 [pid=14719] run-command.c:637 trace: run_command: 'f() { \
myfilter; }; f '\''.gitattributes'\'''
你在跟踪输出中得到了名称,但是调用的命令
实际上并没有用它做任何事情。
所以我最终使用了:
[filter "nbstripout"]
clean = "f() { echo >&2 \"clean: nbstripout \"; nbstripout; }; f %f"
smudge = "f() { echo >&2 \"smudge: cat \"; cat; }; f %f"
required = true
现在我在 运行 和 GIT_TRACE=1
以及没有它的情况下记录了文件名。
在 followup 中,Jeff 建议有一天 git 可能会直接支持这一点,而不需要解决方法。
我正在调试已配置的 git 内容过滤器 (nbstripout
) 的工作,我正试图让 GIT_TRACE
向我显示它正在运行的文件,但是它没有。考虑:
$ GIT_TRACE=1 git pull origin master
[...] removed irrelevant sections of the output
16:49:28.846707 run-command.c:640 trace: run_command: git merge FETCH_HEAD
16:49:28.849309 git.c:344 trace: built-in: git merge FETCH_HEAD
Updating 1ea49ad..ae0ba93
16:49:28.863291 run-command.c:640 trace: run_command: nbstripout
16:49:28.864700 run-command.c:640 trace: run_command: nbstripout
16:49:28.866060 run-command.c:640 trace: run_command: nbstripout
[...] many more of the same
如何让 GIT_TRACE
的 run_command
显示传递给过滤器的参数?我在 git 的手册中查看了各种其他调试环境变量,但我没有看到任何可以启用该级别调试的内容。
我知道 git check-attr
,但我想查看 运行 时间跟踪,其中 运行 过滤了哪些文件以及哪些参数。
git 版本 2.17.1
我在 git 邮件列表和 Jeff King provided a workaround as an answer 上发布了这个问题。在 Jeff 的许可下,我在这里分享他的回答:
GIT_TRACE 应始终显示参数。但除非你指定 clean/smudge 过滤器配置中的参数,那么 Git 将不会通过任何参数。 stdin/stdout 流才是最重要的。
例如:
$ echo '* filter=foo' >.gitattributes
$ git config filter.foo.clean 'myfilter'
$ GIT_TRACE=1 git add .
19:42:16.516401 [pid=14112] git.c:415 trace: built-in: git add .
19:42:16.517454 [pid=14112] run-command.c:637 trace: run_command: myfilter
$ git config filter.foo.clean 'myfilter --foo'
$ touch .gitattributes ;# make sure we actually read it again ;)
$ GIT_TRACE=1 git add .
19:42:58.122942 [pid=14156] git.c:415 trace: built-in: git add .
19:42:58.124023 [pid=14156] run-command.c:637 trace: run_command: 'myfilter \
--foo'
您可以使用“%f”来传递文件名,例如:
$ git config filter.foo.clean 'myfilter %f'
$ touch .gitattributes
$ GIT_TRACE=1 git add .
19:44:51.187177 [pid=14318] git.c:415 trace: built-in: git add .
19:44:51.188256 [pid=14318] run-command.c:637 trace: run_command: 'myfilter \
'\''.gitattributes'\'''
当然,如果您的过滤器确实尊重 争论。对于可能没问题的 "clean" 过滤器(例如,如果它只是告诉 你的过滤器从文件系统而不是标准输入中读取),但它是 几乎肯定不是您想要的 "smudge" 过滤器。
您可以使用一些 shell 技巧来解决它:
git config filter.foo.clean 'f() { echo >&2 "cleaning "; myfilter ...; }; f %f'
然后即使没有 GIT_TRACE,您也会得到:
$ git add .
cleaning .gitattributes
或者,如果您真的只想为 GIT_TRACE 触发,请尝试以下操作:
$ git config filter.foo.clean 'f() { myfilter; }; f %f'
19:52:52.874064 [pid=14719] git.c:415 trace: built-in: git add .
19:52:52.875115 [pid=14719] run-command.c:637 trace: run_command: 'f() { \
myfilter; }; f '\''.gitattributes'\'''
你在跟踪输出中得到了名称,但是调用的命令 实际上并没有用它做任何事情。
所以我最终使用了:
[filter "nbstripout"]
clean = "f() { echo >&2 \"clean: nbstripout \"; nbstripout; }; f %f"
smudge = "f() { echo >&2 \"smudge: cat \"; cat; }; f %f"
required = true
现在我在 运行 和 GIT_TRACE=1
以及没有它的情况下记录了文件名。
在 followup 中,Jeff 建议有一天 git 可能会直接支持这一点,而不需要解决方法。