Git rm several files?

前端 未结 11 1983
长发绾君心
长发绾君心 2020-12-15 05:08

How do I easily remove several files without manually typing the full paths of all of them to git rm? I have plenty of modified files I\'d like to keep so remov

11条回答
  •  甜味超标
    2020-12-15 05:27

    You can give wildcards to git rm.

    e.g.

    git rm *.c
    

    Or you can just write down the names of all the files in another file, say filesToRemove.txt:

    path/to/file.c
    path/to/another/file2.c
    path/to/some/other/file3.c
    

    You can automate this:

    find . -name '*.c' > filesToRemove.txt
    

    Open the file and review the names (to make sure it's alright).

    Then:

    cat filesToRemove.txt | xargs git rm
    

    Or:

    for i in `cat filesToRemove.txt`; do git rm $i; done
    

    Check the manpage for xargs for more options (esp. if it's too many files).

提交回复
热议问题