忽略 Node_modules 資料夾
Ashok Chapagai 2023年1月30日 Git Git Ignore
在處理專案時,你可能不希望 git 跟蹤某些資料夾;這些可以是 .env 檔案、node_modules 資料夾等。
這些資料夾僅供本地計算機使用,不得與其他計算機共享。這可能是因為 node_modules 資料夾的大小可能從幾兆位元組到幾千兆位元組不等。
在工作時,我們肯定不想跟蹤 node_modules 資料夾的許多更改。因此,我們可以使用各種方法來忽略該資料夾。
忽略根資料夾中的 node_modules 資料夾
讓我們採用以下資料夾結構:
. | ├── .gitignore ├── node_modules └── src └── index.html 在這裡,我們需要設定我們的專案,以便我們不包含 git 跟蹤的資料夾 node_modules,這可以通過建立一個 .gitignore 檔案來完成。.gitignore 中提到的檔案/資料夾不會被 git 跟蹤。所以要忽略 node_modules,.gitignore 資料夾內的內容應該如下:
node_modules 忽略整個專案中存在的所有 node_modules 資料夾
為了證明這一點,我們採用具有以下資料夾結構的以下專案:
. ├── backend │ ├── index.html │ └── node_modules ├── frontend │ ├── index.html │ └── node_modules └── .gitignore frontend 和 backend 資料夾中有兩個 node_modules 資料夾,專案根目錄中只有一個 .gitignore 檔案。要忽略兩個 node_modules 資料夾,.gitignore 資料夾的內容必須是:
**/node_modules 在這裡,兩個連續的星號 ** 後跟一個斜槓 / 在所有目錄中匹配以匹配 frontend 和 backend 資料夾中的 node_modules 資料夾。因此,這將使 Git 忽略兩個 node_modules 資料夾。
Enjoying our tutorials? Subscribe to DelftStack on YouTube to support us in creating more high-quality video guides. Subscribe
作者: Ashok Chapagai
