简体   繁体   中英

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:

在此处输入图片说明

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:

在此处输入图片说明

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.

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 .

After reading your comments I think what you really need here is lock file feature, that exists (as far as I know) only on gitlab. But... this requires central server so it's actually against git main idea.

In most cases - as Stony said - you should create template file like config.template.php or config.dev.php , add config.php to .gitignore and make each developer rename/recreate config.php.

Another way would be to create deploy script with transformation instructions that'll automatically adjust paths inside config file, maybe automatically deploy entire application, and run it at each deploy.

Or simply exclude config file every time you commit changes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM