2017-02-26 34 views
1

我嘗試使用.gitkeep,但無論我嘗試過什麼,它都不起作用。如何使用git來追蹤文件夾結構?

比如我有一個文件夾結構是這樣的:

. 
├── a 
│   ├── aa 
│   │   ├── aaa 
│   │   │   ├── .gitkeep 
│   │   │   └── test.txt 
│   │   ├── .gitkeep 
│   │   └── test.txt 
│   ├── .gitkeep 
│   └── test.txt 
├── b 
│   ├── bb 
│   │   ├── bbb 
│   │   │   └── test.txt 
│   │   ├── .gitkeep 
│   │   └── test.txt 
│   └── test.txt 
└── .gitignore 

我有過這樣的的.gitignore:

* 
!a/.gitkeep 
!*/.gitkeep 
!**/.gitkeep 
!.gitignore 

這樣做是爲了保持所有的文件夾與.gitkeep。令人驚訝的是,沒有文件夾將被跟蹤這個配置。

有誰能告訴我爲什麼這不起作用?

+0

你只需要'.gitkeep'文件在沒有任何其他內容的目錄中。在你的情況下,各種'test.txt'文件使它們成爲冗餘。 – jonrsharpe

回答

1

誰能告訴我爲什麼這不起作用?

對於這一點,你的git檢查忽略-v

其次,it is not possible to re-include a file if a parent directory of that file is excluded

而且*會忽略文件夾爲好,使所有其他的排除規則,沒有實際意義。

要僅排除.gitkeep(並忽略保留的文件夾的內容),僅忽略文件,然後將文件夾列入白名單,最後將.gitkeep中的文件夾排除(忽略所有忽略的文件)。

/** 
!/**/ 
!.gitkeep 

但是,如果我們的目標是忽略在文件夾中的任何文件,其中有在它.gitkeep,那麼你就需要逐個排除任何文件夾之一:

/** 
!/**/ 
!/a/aa/aaa/** 
!/b/bb/bbb/** 
+0

非常感謝! '!/ ** /'是關鍵。 '/ **'和'*'實際上具有相同的效果。 – Wang