致命的:命令行,'\/\/( ){0,}beforeEach\(async\(\(\) => \{$':不匹配的 \{

fatal: command line, '\/\/( ){0,}beforeEach\(async\(\(\) => \{$': Unmatched \{

我正在寻找文件列表,其中一些测试被评论为

//     beforeEach(async(() => {
//   beforeEach(async(() => {
 //     beforeEach(async(() => {
//    beforeEach(async(() => {

来自https://regex101.com/

\/\/( ){0,}beforeEach\(async\(\(\) => \{$

工作正常,...但在终端内我得到了

git grep "\/\/( ){0,}beforeEach\(async\(\(\) => \{$"
fatal: command line, '\/\/( ){0,}beforeEach\(async\(\(\) => \{$': Unmatched \{

您需要确保模式符合 POSIX BRE 标准。

使用

git grep "// *beforeEach(async(() => {$"

也就是说,POSIX BRE 表达式中的 ( 匹配文字 ( 并且 { 匹配文字 {.

当您转义左大括号 \{ 时,它会启动一个 范围量词 ,因此 \} 是预期的,因此是错误,Unmatched \{