Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore files with PhpStorm and Git?

I am not able to ignore files which are already under version control.

The "Ignore..." entry is disabled:

enter image description here

1st question: Why is it disabled?

2nd: How to add files afterwards to git ignore?

Thanks a lot!

Edit

PhpStorm says: "This option is only available if a file under the Unversioned Files node is selected. Use this option to ignore the selected file if you want to leave it unversioned."

(Source: https://www.jetbrains.com/help/phpstorm/2016.3/local-changes-tab.html)

But sometimes you may have files for an initial commit, then add it to git ignore to allow local changes (for local development) while not committing / pushing this file to any repo anymore.

Edit 2

Another way I handle this nowadays is to add the changes with credentials to a Changelist which is not committed:

enter image description here

like image 930
Flo Bayer Avatar asked Feb 15 '17 09:02

Flo Bayer


2 Answers

It make no sense to ignore files that are already in your version control. So you have to remove them first with:

git rm --cached filename

then that files exist locally but are removed from your repository. Then you can ignore that files.

like image 124
René Höhle Avatar answered Sep 20 '22 15:09

René Höhle


For the first question, as you found in the link.

For the second question, if you want to ignore a file which has already version controlled by git, you should use git command to do that:

  1. In the local repo, add the file name in .gitignore file. If you don’t have .gitignore, you can use touch .gitignore.
  2. git rm --cached filename.
like image 35
Marina Liu Avatar answered Sep 22 '22 15:09

Marina Liu