You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Git Bash中如何添加指定Livewire目录下含String1的大小写不敏感文件?

Git Add 匹配指定Livewire目录下含String1的文件

问题背景

现有以下Laravel/Livewire文件结构:

app/Livewire/String1Table.php
app/Livewire/String1s.php
app/Livewire/EditString1.php

app/Models/String2Table.php
app/Models/SubDir/SomeString2.php

resources/views/livewire/string1-table.blade.php
resources/views/livewire/string1s.blade.php
resources/views/livewire/edit-string1.blade.php

需要用git add仅添加满足以下条件的文件:

  • 文件名包含String1或string1(忽略大小写)
  • 文件位于Livewire或livewire目录下(忽略大小写)

同时需要验证尝试的命令git add *[Ll]ivewire/*String1[?s]是否正确。

你的尝试命令问题分析

你写的git add *[Ll]ivewire/*String1[?s]存在两个关键问题:

  1. *[Ll]ivewire只能匹配当前目录下的Livewire/livewire目录,无法覆盖app/、resources/views/这类二级目录下的目标文件夹
  2. *String1[?s]中的[?s]仅匹配单个字符为?或s,无法匹配String1Table.php、string1-table.blade.php这类包含更多字符的文件名

正确实现方法

方法1:使用Git原生Glob模式(推荐)

Git支持跨目录的glob匹配,结合字符组实现大小写忽略:

git add **/[Ll]ivewire/**/*[Ss]tring1*

各部分含义:

  • **/:匹配任意深度的前置目录,能覆盖app/、resources/views/等不同层级的路径
  • [Ll]ivewire/:精准匹配Livewire或livewire目录
  • **/:匹配目标目录下的任意子目录(如果存在)
  • *[Ss]tring1*:匹配文件名中包含String1或string1的所有文件,前后的*适配任意前缀/后缀字符

方法2:结合Bash的大小写忽略匹配

如果使用Bash,可以临时开启nocaseglob选项让glob匹配忽略大小写:

# 临时开启大小写忽略的glob匹配
shopt -s nocaseglob
# 执行添加命令
git add **/livewire/**/*string1*
# 可选:关闭大小写忽略(恢复默认)
shopt -u nocaseglob

避免误添加的验证步骤

在执行实际的git add前,建议用--dry-run参数预览将要添加的文件:

git add --dry-run **/[Ll]ivewire/**/*[Ss]tring1*

该命令会列出所有符合条件的文件,确认无误后再去掉--dry-run执行正式添加。

内容的提问来源于stack exchange,提问作者Vicky Dev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 02:33:18