在被忽略的目录中将文件添加到Git

在被忽略的目录中将文件添加到Git,git,Git,我试图包括一个忽略目录中的几个文件,但得到以下结果。我如何包括它们?多谢各位 [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 [Micha

我试图包括一个忽略目录中的几个文件,但得到以下结果。我如何包括它们?多谢各位

[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]$
我的
.gitignore
文件

[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]$
提到(在“”,这说明了我在:

如果文件的父目录被排除,则无法重新包含该文件。(
*

*
:除非满足git 2中的某些条件,请参见下文)

(留言)

如果排除
html/*
,则排除的是内容,而不是文件夹本身,允许使用
!xxx
要应用的规则

请注意,要始终检查忽略特定文件的原因,可以键入:

git check-ignore -v -- html/about-us.html
这将为您提供
.gitignore
文件的确切行,这是导致
git add
无法工作的原因


请注意,使用git 2.9.x/2.10(2016年年中?),如果文件的父目录被排除,则可能会重新包含该文件

正在尝试添加此功能:

  • 对于git v2.7.0,在git v2.8.0-rc0中恢复
  • git v2.8.0-rc0,。。。在git 2.8.0-rc4中恢复了(!)
在您的情况下,可以工作的(使用git 2.?+)应该是:

/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

您可以
git add--force yourFile
强制将文件添加到git,而不考虑
.gitignore
@Seiyria。是的,我看到了回复,但不知道为什么我要做一些需要强制的事情。你忽略了html目录。这真的那么令人惊讶吗?第一行应该是
/html/*
参见@ShawnBalestracci。非常感谢。我读过其他类似的SO帖子,但这篇文章很成功。