0

I am trying to include a couple of files which are in an ignored directory, but get the following. How do I include them? Thank you

[Michael@devserver bidjunction]$ git add html/about-us.html
The following paths are ignored by one of your .gitignore files:
html/about-us.html
Use -f if you really want to add them.
fatal: no files added
[Michael@devserver bidjunction]$

My .gitignore file

[Michael@devserver bidjunction]$ cat .gitignore
/html/
/ayb_cache/
/ayb_resources/

#Some cache files in the main application
/ayb_application/lib/plugins/tinymce_plugins/imageManager/cache/
/ayb_application/lib/plugins/tinymce_plugins/image_purchased/cache/
/ayb_application/lib/plugins_3rd/tinymce_4.0.6/plugins/image/cache/

# Temp files often created by editors
*.~

# Track some files in html directory
!/html/css/
!/html/images/
!/html/scripts/
!/html/about-us.html
!/html/corporate.php
!/html/index.html
!/html/muse_manifest.xml
!/html/terms-and-conditions.html
[Michael@devserver bidjunction]$
user1032531
  • 24,767
  • 68
  • 217
  • 387

1 Answers1

2

Shawn Balestracci mentioned (in the comments) ".gitignore exclude folder but include specific subfolder", which illustrated what I mentioned in this answer:

It is not possible to re-include a file if a parent directory of that file is excluded. (*)
(*: unless certain conditions are met in git 2.?, see below)

(A message introduced with git 1.9.x)

If you exclude html/*, you are excluding content, not the folder itself, allowing the !xxx rules to apply.

Note that to check at all time why a particular file is ignored, you can type:

git check-ignore -v -- html/about-us.html

That will give you the exact line of your .gitignore file which is the cause of your git add not working.


Note that with git 2.9.x/2.10 (mid 2016?), it might be possible to re-include a file if a parent directory of that file is excluded if there is no wildcard in the path re-included.

Nguyễn Thái Ngọc Duy (pclouds) is trying to add this feature:

In your case, what could work (with git 2.?+) would have be:

/html
!/html/css
!/html/images
!/html/scripts
!/html/about-us.html
!/html/corporate.php
!/html/index.html
!/html/muse_manifest.xml
!/html/terms-and-conditions.html
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250