0

I want to add a new directory to a project, but I am not able to do that.

If I do git status the new directory does not show.

If do git add -A nothing happens, when I do git status the directly does not show.

There is not gitignore (that I can find at least...)

There is an exclude file that contains:

Foo.Mobile\platforms\android\assets
Foo.Mobile/platforms/android/.idea/workspace.xml

But I don't think that is the problem. The directory I have created is inside:

C:\Users\Bar\git\FooAndroid\Foo.Mobile\platforms

And there is a sparse-checkout file that contains

Foo.Mobile/platforms/android/*

And again I don't think that is the problem.

The project is IntelliJ based.

Thanks

Trevor Reid
  • 3,310
  • 4
  • 27
  • 46
Lisa Anne
  • 4,482
  • 17
  • 83
  • 157

2 Answers2

3

Git does not provide for working with empty directories or files. Try creating a dummy file in the directory.

The reason for this is that Git works only on changes in files and if there is no text it can not compare anything.

A diff file also contains the location (directory) to the file and thus automatically adds the directory.

Here is a solution if you really want to keep an empty directory in Git.

Trevor Reid
  • 3,310
  • 4
  • 27
  • 46
Genkus
  • 151
  • 6
2

First, you must ensure that there is a file in the directory you're adding, since git only operates on files. Since you've already done this, the next thing to do is to trouble-shoot.

Using git add . will only add from the current directory downward; if used, it must be from the root of the repository. Sometimes, git add --all will be easier and more appropriate.

You need to look for a .gitignore file. Notice there is a "dot" at the beginning of the file; on most operating systems (and certainly Windows), these files are classified as "system" files and are hidden by default; you can, however, make them visible in an operating-system-dependent manner. The .gitignore should be at the root level of the repository you cloned, but sometimes there may be more than one in different directories. Using a command-line or GUI tool may help find any .gitignore files that may exist.

If you're looking at a .gitignore file, be sure that you understand any regular expressions which may be inadvertently matching the file you're trying to add. You could, as a simple test, try renaming the .gitignore and trying the add again, but be ready to unstage the files that will be added as a result. You could also try git check-ignore -v <dirname>, or read the help for check-ignore for more advanced options. Some useful help on this is offered by git help gitignore.

If all else fails, try adding an arbitrary test file, to ensure that something else is not wrong with the repository.

rholmes
  • 4,064
  • 3
  • 25
  • 34