Search code examples
gitphpstormgitignore

problem with ignoring files/folders that are already in the remote repository (github)


I am working on PhpStorm. There are some files/folders that I would like git to ignore. These are on the remote repository, too. I just don't want to reflect any more changes about them but they have to stay - not be deleted - from remote repo since I am going to pull from this repo to the production server.

  • I have added them to the .gitignore file which is in the project root.
  • I have added them to PhpStorm Settings > Version Control > Ignored Files section as described here https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000154070-How-to-gitignore-idea-files
  • How to ignore files which are in repository? this question describes my problem exactly, yet I have tried both methods which are described in the accepted answer, here is what happened:
    • git rm -r --cached .idea/ I did this and related files/folders were deleted from my remote repository too, which I don't want because I think it will result in deleting those when I pull on the production server.
    • git update-index --assume-unchanged .idea/ I did this, "Ignoring path .idea/" was written in the terminal, I hoped that it would work but when I wanted to commit, I saw that folder again as tracked.

What am I doing wrong?

Note: .idea folder may not be important for the production server, but there are some important folders needed for the code to run.


Solution

  • I discovered where I was wrong. For those who may need, I will explain it with two folders I have:

    • config/ and config.php under it
    • pdf/ and pdf.css under it

    So:

    git update-index --skip-worktree config/
    

    Running this and changing config.php didn't help. On the other hand:

    git update-index --skip-worktree pdf/
    

    After running this I got a pdf output from my web application and it created pdf.html also under pdf/ folder. So, this new file was ignored, good.

    Shortly, I concluded that I had to point out the exact file if that's what I want to be ignored, like this:

    git update-index --skip-worktree config/config.php
    

    It ignores any changes to this file afterwards.

    (I tried the same with --assume-unchanged, it worked, yet since I have understood the difference very well from the answer above, I wanted to highlight the better way here)