[英]How can I make shell script to recursively scan a directory and add certain files based on their name patterns to Git?
How can I make shell script to recursively scan a cloned Git directory and remove certain files based on their name patterns?如何使 shell 脚本递归扫描克隆的 Git 目录并根据名称模式删除某些文件? If the file meet any of the below condition,
如果文件满足以下任一条件,
If any of the file matches, it should be executed with git rm </path/to/file/file name>
如果任何文件匹配,则应使用
git rm </path/to/file/file name>
Thanks in advance.提前致谢。
Use find
for the scanning:使用
find
进行扫描:
find . -regextype egrep \( -name .git -prune \) -o \
\( -type f -regex '.*(:[^/]*|[^/]{151,})$' -exec git rm '{}' \+ \)
(Do a dry run without the -exec
bit first to make sure it works as desired, of course) (当然,先在没有
-exec
位的情况下进行试运行以确保它按预期工作)
Note: This assumes GNU find
, since you tagged the question linux
.注意:这假定 GNU
find
,因为您标记了问题linux
。
This tells find
to skip any .git
subdirectories, and for all other regular files in the directory tree, if the last /
-separated component (The filename + extension if any) has a colon or 151 or more characters in it, pass it off to git rm
.这告诉
find
跳过任何.git
子目录,对于目录树中的所有其他常规文件,如果最后一个/
分隔的组件(文件名 + 扩展名,如果有)有冒号或 151 个或更多字符,则将其忽略到git rm
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.