Marco Agliani Marco Agliani - 4 years ago 161
Git Question

Remove file now ignore with gitignore (only from a folder)

I've a problem with a project stored in a git repository. I've created three different branches (master, v1, v2) and sometimes I updates branches v1, v2 downloading the content from the master branch through this code:

git checkout master
git pull
git checkout release/demo
git merge master
git push


In this project I've got a folder named "image" (present on all branches), and I need the contents of this folder (with some exceptions) not to be synchronized during the merge. In order to do that, I've created a .gitignore file containing this code:

*
!.gitignore
!placeholder_300_150.png
!placeholder_450_50.png


The problem is that the different branches already contain multiple versions of different files in this folder, and this causes many problems during the merge. How can I delete all versions of ignored file from my repository (if possible without working on all projects but only on this folder)?

Answer Source

If I am not wrong, you are wanting to ignore your image directory during commit/pull/push. For this, clear your git cache. Add image directory in your .gitignore file.

$ git rm --cached -r image

# add just image in .gitignore file
image/ 

# add, commit and push the changes to remote
$ git add .
$ git commit -m 'Updated .gitignore'
$ git push origin HEAD
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download