1

I have a repository where I am ignoring a whole directory, however there is an individual directory inside there that I want to be a submodule. So my git ignore file has the line,

wp-content/plugins/

I was planning on adding the line

!wp-content/plugins/my-plugin

So it would then track only the submodule code, correct?

So I attempted to add it as a submodule and was given a "use -f flag" message. So I did. Now git status shows that plugin even though the directory is still ignored.

Does the -f force it to override the git ignore directives? And if so, can I then just omit the ! like in my ignore file and commit it all?

Thank you.

thatryan
  • 1,551
  • 6
  • 21
  • 39

2 Answers2

0

If this hasn't changed since "Git ignore all except subfolder", your ignore rules would be:

wp-content/plugins/*
!wp-content/plugins/my-plugin

Note that I wouldn't use a trailing slash (as you did) for my-plugin, since adding a submodule would add a gitlink entry in the index, called my-plugin.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

You are mixing up ignoring folders and submodules, but they are two different things really. If you want to have that plugin exist in your repository as a submodule, it shouldn't be ignored there (as submodules are different entities in your repository by design).

What you need to do from here to fix this situation, is temporarily move the my-plugin folder out of the repository entirely. Then remove the !wp-content/plugins/my-plugin line from your .gitignore file, as it's no longer needed and commit that state of your repository.

Now make sure that your my-plugin is in a separate repository (as is required for it to be added as a submodule) and add that submodule to your main repository. That should do the trick.

Coen Jacobs
  • 121
  • 1
  • 5
  • OK so they are done two different ways then? By adding a submodule it "overrules" the gitignore of the entire directory? So I do not need to explicitly allow it? Also, note that I never added the !wp-content/plugins/my-plugin line I just meant that was what I was going to do... – thatryan Sep 16 '14 at 06:49
  • It's something different entirely. To explain it in your words, yes it would "overrule" the rules in the gitignore, but the files in the submodule aren't actually tracked by the parent repository. – Coen Jacobs Sep 17 '14 at 09:27