Symfony .gitignore ignores too much - php

I have a Symfony 3 project.
In the root dir is the usual vendor dir that composer uses for installation.
In the web dir I also have a vendor dir for bootstrap, fontawesome etc.
In .gitignore I have an entry vendor.
Unfortunately both vendor dirs are ignored. But I want to commit the web/vendor dir.
How is that possible?
May be I have found a solution. I added !web/vendor to the .gitignore.
Is this the right way?

gitignore will recursively ignore everything that matches the "vendor" pattern if that is all you have in your gitnore.
There are some basic rules about gitignore you should familiarize yourself with.
The one here is that gitignore will run relative to the directory it's in.
So, if you add a /vendor entry to the .gitignore in your root dir, then it will only ignore the vendor directory in your root dir. Leave out the slash, and it will drill down as far as it can go and ignore everything that has a vendor in the name, whether it be a file, directory, whatever.
A tip: try looking up sample .gitignore files on github for a specific project type you're using. These are usually good enough to get going.
For symfony, a good one is here: https://github.com/github/gitignore/blob/master/Symfony.gitignore

Yes, that was the right way. Just add !web/vendor.

Related

PhpStorm disable watching for vendor git repositories

I am using git and PhpStorm for my project. When i trying to push, or pull, or to do any else action, i also see git repositories from /vendor (composer).
How to disable they for PhpStorm?
UPDATE:
/vendor already in .gitignore
# composer vendor dir
/vendor
In the root of your project just create/edit the .gitignore file and add the following
/vendor
You can do this for any directory you would like
if you want to include a sub-directory of a directory you exclude just add something like this.
!/vendor/bin
Here are the relevant git docs about it:
https://git-scm.com/docs/gitignore
Edit: I saw you did indeed have a correct .gitignore [assumption based on your reaction to the comment] If you have already worked with a file in phpstorm and added it to the ignore pattern later phpstorm does nothing with it, you should be manually removing the folder from your machine and from the repo [by deleting and commiting/pushing].
Just delete it and commit it to origin. and just use composer to reinstall. voila!
I find the solution! It was in File->Settings->Version Control. I Just unregister vendor roots. Thank all for help!
Do not know if very correctly applicable, but my search leading to this question was solved by applying "git reset" command on files I added prior adding them to a .gitignore file.

Where should the composer.json and composer.lock files should be?

I've never used Composer before, but installed it so I could set twig up the recommended way.
I now have composer.json and composer.lock files in two separate directories. How do I determine where they SHOULD be? I assume they certainly shouldn't be in my public html root, as one of them has managed to be?
The composer.json file should be created at the topmost directory of your project, i.e. the top directory that is in version control. Subdirectories of this directory likely are for example the "public" or "htdocs" or "www" directory which is the document root for the web server.
By using Composer, this directory will also get a "vendor" directory where the packages are being placed, as well as the composer.lock file which records the exact versions being installed.
Do commit both composer.json and composer.lock. Don't commit the vendor folder, put it onto the ignore list.

Move a Git repository to another directory

I want to move a git repository to a sub-directory which is there in its present root folder.
Let me explain the things first.
I have Git repository testing in $HOME/repos/ (contains PHP code-base).
Now i want to move testing into $HOME/repos/php/ where php will be sub-directory which i want to create (anyway php directory is not a git repository)
My questions are
if i do above explained move then does this effect my testing repository ?
Does this effect any branches or commits or uncommitted changes in testing repository ?
Moving a repository to a different directory should have no effect on the repository. Simply move everything as you would with any other kind of files, taking care to move the .git directory along with it. That .git directory is what git looks at and compares against other stuff in the project directory (wherever that .git directory lives).

Gitignore Laravel vendor folder

Right now I have /vendor set in my gitignore file.
But how do I ignore all folders inside /vendor except one folder.
Eg: I want git to track /vendor/MyFolder but not any other folders in /vendor
In a .gitignore you can use the ! operator to "unignore" files.
The following example will ignore everything in the vendor directory, but anything in vendor/MyFolder will be "unignored"
vendor/
!vendor/MyFolder

Gitignore error_log.txt

What rules should i add to .gitignore to ignore all error_log.txt files generated in php?
I have tried adding simply error_log to it, but it doesn't seem to work.
Im working on a Win7 x64 and i am new to Git.
To ignore a file (like error_log.txt) in all directories of your repository, you should add the following rule to the .gitignore in the root folder of your repo:
error_log.txt
As said, that will ignore all files called error_log.txt in all directories and subdirectories of the repo.
Be aware, that .gitignore does only ignore files that are not tracked yet. If you have added and commited a error_log.txt already, that file will stay tracked. See Ignore files that have already been committed to a Git repository for futher detail on that.

Categories