I'm having a strange issue with Git. I use Composer to include TCPDF in my application, but I can't get it added to my repository.
Here's what I do step-by-step:
The status quo. These are just plugins; it's lacking the 'tcpdf' folder I need.
Now I run Composer to have it install the additional directory.
In this picture, it's already clear that something is wrong. Composer downloaded all files and folders and TCPDF is functioning on my machine, but only the tcpdf folder is shown red. The subfolders are not! I go to the command line and do 'git add .', so that it adds all files and folders. Now it looks like this:
Still wrong.
The wrong status is reflected by git status
:
I'm really stuck here. I have no idea how to tell Git that this isn't a file but a folder. My repo is perfect, but if my colleague updates he only gets this file, without the folder content.
How do I fix this?
All of the local git "stuff" is placed in the . git folder in your "local repos" a.k.a. "working folder/directory". Folder/directory here is a folder that can contain other folders/directories - as well as files - indeed it will always contain a . git folder, otherwise it would not be a repository.
You shouldn't store credentials like usernames, passwords, API keys and API secrets. If someone else steals your credentials, they can do nasty things with it.
initialize a new repo to serve as the child repo. move everything from the subdirectory of the parent repo work tree to the child repo work tree. commit the child repo. replace the subdirectory in the parent repo with a submodule reference.
Since you've done your copy-contents-then-move workaround there's no easy way to test this, but I suspect your tcpdf/
directory contained its own .git/
.
Git handles nested directories by creating a special "gitlink" file in the parent repository. When you copied the contents from the tcpdf/
directory into the test
directory you could easily have missed the hidden .git/
directory, which means that directory is no longer a nested repository.
With Composer, this could have happened if you used composer require --prefer-source
or similar. This is the default if you're using an unstable version.
While some developers like to track the vendor/
directory that Composer creates it's not recommended:
Should I commit the dependencies in my vendor directory?
The general recommendation is no. The vendor directory (or wherever your dependencies are installed) should be added to
.gitignore
/svn:ignore
/etc.The best practice is to then have all the developers use Composer to install the dependencies. Similarly, the build server, CI, deployment tools etc should be adapted to run Composer as part of their project bootstrapping.
That page goes on to explain why this recommendation exists. I recommend reading the entire page. If you follow this best practice it won't matter if you use --prefer-dist
or --prefer-source
.
In general, both the composer.json
and composer.lock
files should be tracked.
Late to the party, as usual, but I stumbled here so others might too.
I had this issue(1) when I accidentally left a .git
folder in a sub-folder within my git repo.
I solved it by clearing my local git's cache:
git rm -rf --cached .
(notice the full-stop at the end!).
See git rm -?
for info on the flags.
(1) git thought a folder was a single file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With