在這里混。
我的專案結構將如下所示:
app/
README.md
.gitignore
src/
<all source code goes here>
docs/
<docs go here>
misc/
examples/
<examples go here>
fizzbuzz/
properties/
configs/
該misc/fizzbuzz/properties/目錄非常特殊,我希望能夠.gitignore為它設定一些特殊的配置。在這個目錄中,我將有許多子目錄,如下所示:
app/
README.md
.gitignore
src/
<all source code goes here>
docs/
<docs go here>
misc/
examples/
<examples go here>
fizzbuzz/
properties/
abc/
def/
ghi/
...etc.
configs/
每個子目錄 (of properties/) 都將遵循相同的模式:
abc/
abc.properties
abc.txt
many many other files...
def/
def.properties
def.txt
many many other files...
ghi/
ghi.properties
ghi.txt
many many other files...
所以在每個子目錄中都會有:
- 一個屬性檔案,其名稱與其所屬的子目錄的名稱完全相同(
ghi.propertiesunderproperties/ghi/等);和 - 一個 txt 檔案,其名稱也與其所屬的子目錄的名稱完全相同(
ghi.txtunderproperties/ghi/等);和 - Many, many other files. Some will be
ghi.*(a "ghi" file, just not of type properties or txt). Some will be*.propertiesor*.txt(other properties files or txt files, just notghi.propertiesorghi.txt, etc.). Some will be named all over the place (foobar.mp4,flam.csv, etc.). But the thing these files have in common is that they are not of the form "<parent-dir-name>.properties" or "<parent-dir-name>.txt".
I am trying to configure .gitignore to ignore everything in these child directories except for the properties and txt file that matches the name of the directory they live inside of.
Can anyone help nudge me in the right direction?
uj5u.com熱心網友回復:
手工撰寫一個簡單的 .gitignore 檔案似乎很簡單:
abc
!abc/abc.properties
!abc/abc.txt
def
!def/def.properties
!def/def.txt
# ...etc.
生成此類 .gitignore 檔案的簡短 Bash shell 腳本可能如下所示,但更易讀的版本basename可能會更清晰:
cd app/...../properties
for i in */; do printf "%s\n" "${i%/}" '!'"$i${i%/}."{properties,txt}; done > .gitignore
可以將這樣的腳本添加到 git-commit 掛鉤或生成檔案夾的自動化中。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/435156.html
