简体   繁体   中英

How do you gitignore all single file extension files from a git repository after committing?

I'm new to using git and was wondering how do I remove all cached .exe files from a git repository (I want to keep them in my working folder). The root folder has subfolders that also have the .exe files. Will the following command work or do I have to do something else? I understand the -r is for removing directories and not files and it just seems wrong, and on searching about this topic, only relevant thing I found was using find and delete commands, but I'm not sure about how to use them.

git rm --cached -r *.exe

Edit: I ran the command and it only removed the .exe from root folder not the sub folders Is manually listing all sub folder paths and running that command the only option?

Since passing the git command with it's cached flag is required, for people who are unfamiliar with chaining commands in linux/ unix, the recursive remove unix answer is not sufficient.

This should do it (in an sh compatible shell):

find . -name '*.exe' -exec git rm --cached '{}' \;

Alternatively, less elegant but easier to compose:

ls -R | grep '.exe$' | xargs git rm --cached

The trouble with your git rm -r command is that it will only recurse into directories whose name ends with .exe , which is obviously not what you want.

Escape the wildcard so Git sees it rather than your shell:

git rm -n --cached \*.exe

(then rerun without the -n if you like what you see)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM