0

I've got an issue with contents of a directory not being including with git. It doesn't appear in .gitignore which seems to be the solution to similar questions.

Here's my .gitignore:

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/client/build

# misc
.DS_Store
.env
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

The directory is "server", which appears, however no contents are within it when running git ls-tree -r main --name-only.

Here's my root directory.

enter image description here

Any ideas?

Thanks in advance!

auley_code
  • 67
  • 1
  • 8
  • 1
    Did you `git add` it? – Eugene Sh. Dec 02 '21 at 19:02
  • Does this answer your question? : [git ls-tree output of working directory?](https://stackoverflow.com/q/10082514/2915738) – Asif Kamran Malick Dec 02 '21 at 19:05
  • Does this answer your question? https://stackoverflow.com/questions/115983/how-can-i-add-a-blank-directory-to-a-git-repository – match Dec 02 '21 at 19:14
  • There are two obvious possibilities: (1) `server` is empty (has no files): Git only stores files, not directories, so that would do it. But that looks wrong based on the image you included. (2) `server` *is a Git repository*. A Git repository is **not allowed** to contain another Git repository; an attempt to add one results instead in a submodule (or, if added incorrectly, what I like to call a "half-assed submodule" that doesn't do anything useful for most users). – torek Dec 02 '21 at 20:02
  • @EugeneSh. yes. Tried removing and adding that directory again but still only showing "server" and not all the contents when running git ls-tree -r main --name-only – auley_code Dec 02 '21 at 20:03
  • @torek (1) yes there are files within those folder as you mention. (2) I did have a .git in that folder but removed it so that it is only in the root folder – auley_code Dec 02 '21 at 20:05
  • If you ran `git add` while the `.git` in there, your Git has added to your index / staging-area a *gitlink* entry. This is the "half assed" submodule. Its existence will prevent adding any files from that directory and you will need to remove it. If you made any commits while this gitlink was in place, those commits are defective (whether you choose to do anything about this is up to you, the defect is somewhat minor). – torek Dec 02 '21 at 20:08
  • To remove a gitlink (a half-assed submodule), use `git rm --cached server`. To remove a proper submodule, search StackOverflow. Modern Git has a nicer way to clean up, older Git versions require complicated stuff. – torek Dec 02 '21 at 20:10
  • Thanks @torek. I did try that before from another question/solution but didn't solve it. I guess creating a new folder with the files and removing this one could solve it – auley_code Dec 02 '21 at 20:15
  • 1
    Note that `git ls-tree -r` looks at an existing commit. You want `git ls-files --staged` to see what files are scheduled to go into the *next* commit. – torek Dec 02 '21 at 20:19

0 Answers0