Git - 从存储库中删除所有类型的文件 [英] Git - Remove All of a Certain Type of File from the Repository
问题描述
如何从存储库中删除所有特定类型的文件?我使用
git filter-branch --index-filter'git rm -rf --cached ** / *。 jar'
git没有扩展globs,也没有扩展 **
按照我的预期。 > git filter-branch --index-filter'git rm -rf --cached ** / *。jar'
应该可以工作,但它有点愚蠢,因为git globs( *
)匹配路径分隔符。因此, ** / *。jar
相当于 *。jar
。
这也意味着 * / a * .jar
匹配 dir1 / abc / dir2 / log4j.jar
。如果您想匹配 ** / a * .jar
(任何名称以> a
开头的所有罐子)目录),你应该使用find。这是一个命令,用于删除名称以 a
或 b
开头的任何罐子,以及 dir1 / dir2
和任何目录中的任何.txt文件:
git filter-branch - -index-filter'git rm -rf --cached* .txtdir1 / dir2 / *。jar$(find -type f -namea * .jar-o -nameb * .jar )'
参考文献: pathspec
code> git help词汇表。
How do I remove all of a certain type of file from the Repository? I'm using
git filter-branch --index-filter 'git rm -rf --cached **/*.jar'
Either git is not expanding globs, or it isn't expanding **
in the way I'm expecting.
git filter-branch --index-filter 'git rm -rf --cached **/*.jar'
should work, but it's a bit silly because git globs (*
) match path separators. So, **/*.jar
is equivalent to *.jar
.
This also means that */a*.jar
matches dir1/abc/dir2/log4j.jar
. If you want to match something like **/a*.jar
(all jars whose name starts with a
in any directory), you should use find. Here's a command to remove any jars whose names start with a
or b
, and any jars in dir1/dir2
, and any .txt file in any directory:
git filter-branch --index-filter 'git rm -rf --cached "*.txt" "dir1/dir2/*.jar" $(find -type f -name "a*.jar" -o -name "b*.jar")'
References: pathspec
section of git help glossary
.
这篇关于Git - 从存储库中删除所有类型的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!