code-8
code-8

Reputation: 58632

Untrack a certain folder via GIT

I don't want to track all the file inside my account folder

I've tried adding /public/images/account/* to my .gitignore file

Every time, I did git status , I still get

modified: public/images/account/1001/logo.png

What did I do wrong here ?


I've also tried adding /public/images/account/*/logo.png to .gitignore

Upvotes: 0

Views: 569

Answers (2)

Julien Carsique
Julien Carsique

Reputation: 3995

Once a file has been added (git add), .gitignore has no effect on it.

Removing a file from the cache (git rm --cached) will make it then being properly ignored if mentioned in .gitignore:

git rm --cached <files_to_remove>
git commit

However, the file removal action is stored by Git and will be applied every time the corresponding commit is replayed; and the file will still be present in previous commits. That is often an issue for files which should have never been added (IDE user-specific configuration files for instance) during merge, rebase, cherry-pick and so on. So, if modifying the history is acceptable, then the following solution is better:

# This action modifies the Git history! All commits previously containing the unwanted files will be rewritten.
git filter-branch --index-filter 'git rm -r --cached --ignore-unmatch <files_to_remove>' HEAD

Upvotes: 0

Steve Barnes
Steve Barnes

Reputation: 28370

As you are being told that these files are modified that means that they have been added to the repo you also need to forget the files that you already added by using git rm

Upvotes: 1

Related Questions