Git不跟蹤目錄,它跟蹤文件,因此爲了達到這個目的,你需要跟蹤至少一個文件。因此,假如你.gitignore
文件看起來是這樣的:
upload/*
你可以這樣做:
$ touch upload/.placeholder
$ git add -f upload/.placeholder
如果您忘記了-f
你會看到:
$ git add upload/.placeholder
The following paths are ignored by one of your .gitignore files:
upload
Use -f if you really want to add them.
fatal: no files added
然後,當你做git status
你會看到:
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached ..." to unstage)
#
# new file: upload/.placeholder
#
很明顯,你可以再做:
$ touch upload/images/.placeholder
$ git add -f upload/images/.placeholder
Git只跟蹤文件。你可以做的就是使用git鉤子,並跟蹤一個包含目錄列表的文件(使用鉤子自動生成)。雖然我不完全確定這是否可能。 – 2011-02-23 12:49:58
更具體:Git跟蹤_content_和(for git)空目錄不是內容。你可以爭論,不管你是否同意,但作爲另一種「解決方法」,你可能會考慮在build/install/when-needed上創建目錄。但是:我使用「'.placeholder'-file」 - 解決方案也;) – KingCrunch 2011-02-23 13:00:11
而不是使用.placeholder,我使用.gitignore文件。這不僅處理目錄中的排除事項,而且它本身充當佔位符。 – Abizern 2011-02-23 13:04:43