2014-05-04 59 views
0

我想包含一些文件在忽略的目錄中,但得到以下內容。我如何包含它們?謝謝將文件添加到忽略的目錄中的Git

[[email protected] 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 
[[email protected] bidjunction]$ 

.gitignore文件

[[email protected] 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 
[[email protected] bidjunction]$ 
+3

您可以'GIT中添加--force yourFile'強制文件被添加到混帳不管'.gitignore'。 – Seiyria

+0

@塞里亞。是的,我看到了答案,但想知道我爲什麼要做一些需要武力的事情。 – user1032531

+2

你忽略了html目錄。這真的令人驚訝嗎? – FDinoff

回答

1

Shawn Balestracci(在the comments) 「.gitignore exclude folder but include specific subfolder」 所提到的,這說明我在this answer提到:

這是不可能重新如果排除該文件的父目錄,則包含一個文件。 (*
*:?除非某些條件,在git的2相遇,見下文)

(A消息introduced with git 1.9.x

如果排除html/*,你是不包括的內容,而不是文件夾本身,允許應用!xxx規則。

注意,在所有的時間檢查某個特定的文件將被忽略,你可以輸入:

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

這會給你.gitignore文件的確切行這是你的git add不工作的原因。


注意用git 2.9.x/2.10(2016年年中?),有可能再包括一個文件,如果該文件的父目錄排除if there is no wildcard in the path re-included

Nguyễn Thái Ngọc Duy (pclouds)正在努力增加這個功能:

在你的情況,有什麼可以工作(使用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