本文介绍了.gitattributes模式中的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一些git工具,它们使用涂抹/清洁过滤器,因此我必须在.gitattributes文件中创建条目.

I am writing some tools for git that make use of smudge/clean filters, and so I must create entries in the .gitattributes file.

不幸的是,该文件是通过在空格上拆分来简单地解析的,因此,在我看来似乎不可能在模式中包括一个明确的空格字符.

Unfortunately, that file is parsed rather simply by splitting on whitespace, and so it is does not seem possible to me to include an explicit space character in the pattern.

我一直在用?替换空格字符,该字符再次匹配零个或一个字符.

I have been replacing whitespace characters with ?, which matches again zero or one characters.

Ergo,has?spaces的模式将与我的目标文件名has spaces以及hasspaces匹配.

Ergo, a pattern of has?spaces will match against my target filename of has spaces, but also hasspaces.

是否有一种只能匹配空格的方法,还是我陷入了近乎匹配的境地?

Is there a way to only match spaces, or am I stuck with the near-match?

推荐答案

作为模式的一部分,您可以尝试:

You can try, as part of your pattern:

[[:space:]]
# as in
has[[:space:]]spaces

gitattributes手册页确实提到了示例.
而且模式测试还包括几个示例:

The gitattributes man page does mention an example with it.
And the pattern tests also include several examples:

match 1 x ' ' '[[:digit:][:upper:][:space:]]'

这篇关于.gitattributes模式中的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 05:32