Git - Remove All of a Certain Type of File from the Repository

前端 未结 5 1437
情歌与酒
情歌与酒 2020-12-31 05:54

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\'
5条回答
  •  情歌与酒
    2020-12-31 06:08

    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.

提交回复
热议问题