使用 .gitignore 忽略除特定目錄之外的所有內容 - Using .gitignore to ignore everything but specific directories

問題:

My issue is that I have a bunch of WordPress websites in my git repo, of which I want to selectively commit only the content of my themes folders, while ignoring the rest of the redundant files found in WordPress.我的問題是我的 git 存儲庫中有一堆 WordPress 網站,其中我想有選擇地只提交我的themes文件夾的內容,而忽略在 WordPress 中找到的其餘冗餘文件。

I've used .gitignore files to ignore file types before, but can it be used the other way around- that is to ignore everything BUT a certain folder path?我之前使用過 .gitignore 文件來忽略文件類型,但是可以反過來使用它 - 即忽略除某個文件夾路徑之外的所有內容嗎?

root (git repo)根(git repo)
- / wordpress - / wordpress
- - / (WordPress Site 1)/wp-content/themes - - / (WordPress 站點 1)/wp-content/themes
- - / (WordPress Site 2)/wp-content/themes - - / (WordPress 站點 2)/wp-content/themes
- - / (WordPress Site 3)/wp-content/themes - - / (WordPress 站點 3)/wp-content/themes

Thanks-謝謝-

UPDATE:更新:

Based on the answers I did the following, but it's not working.根據答案,我做了以下操作,但它不起作用。 Any ideas?有任何想法嗎?

# Ignore everything:
*
# Except for wordpress themes:
!*/wp-content/themes/*

I've also tried the following variations:我還嘗試了以下變體:

!*/wp-content/themes*
!*wp-content/themes/*
!wp-content/themes/*
!/wordpress/*/wp-content/themes*
!wordpress/*/wp-content/themes*

None of these read my themes folders.這些都沒有讀取我的themes文件夾。


解決方案:

參考一: https://en.stackoom.com/question/Lzae
參考二: https://stackoom.com/question/Lzae
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章