我在使用带有路径规范的 git-status 时观察到一种奇怪的行为。我希望您对它是预期行为还是 git 中的未定义行为提出意见。
初始设置
$ mkdir main && cd main
$ git init .
Initialized empty Git repository in d:/temp/main/.git/
$ touch test[1].txt
$ touch test[2].txt
以下几条可以理解
$ # 1. escaped square brackets
$ git status test\[1\].txt --short
?? test[1].txt
$ # 2. escaped square brackets with range
$ git status test\[[1-9]\].txt --short
?? test[1].txt
?? test[2].txt
$ # 3. unmatched range, with what looks like a fallback to literal comparison
$ git status test[1].txt --short
?? test[1].txt
意外行为的附加设置
$ touch test1.txt
意外行为
$ # 4. matched range, so no fallback to literal comparison (this one looks OK)
$ git status test[1].txt --short
?? test1.txt
$ # 5. escaped square brackets => I would expect only test[1].txt to be returned
$ git status test\[1\].txt --short
?? test1.txt
?? test[1].txt
$ # 6. escaped square brackets with range => I would expect only test[1].txt
$ # and test[2].txt to be returned
$ git status test\[[1-9]\].txt --short
?? test1.txt
?? test[1].txt
?? test[2].txt
$ # 7. only escaping the last square bracket
$ # result looks similar to the 5th case
$ git status test[1\].txt --short
?? test1.txt
?? test[1].txt
额外设置带来更多乐趣
$ git add test1.txt
$ rm test1.txt
$ touch test2.txt
更多意外行为
$ # 8. ???
$ git status test[1].txt --short
AD test1.txt
?? test[1].txt
$ # 9. We lost test1.txt ???
$ git status test[1-2].txt --short
?? test2.txt
$ # Woo... Should this really work?
$ git status test[*.txt --short
AD test1.txt
?? test2.txt
?? test[1].txt
?? test[2].txt
我在那里有点困惑。我已经阅读了与pathspec相关的 Git 文档,但并没有那么详细。
谁能帮我理解背后的逻辑?