Xgh05t
Xgh05t

Reputation: 240

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.

Upvotes: 0

Views: 110

Answers (2)

jthill
jthill

Reputation: 60235

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)

Upvotes: 0

Thomas
Thomas

Reputation: 181705

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.

Upvotes: 1

Related Questions