鍍金池/ 問答/Linux  HTML/ .gitignore配置問題

.gitignore配置問題

我現(xiàn)在想實現(xiàn)git同步的時候忽略node_modules下面除了@wang以外的文件夾,也就是說保留@wang文件夾,應(yīng)該怎么樣配置.gitignore文件呢

回答
編輯回答
情皺

其實這類問題,git文檔上已經(jīng)寫了,只是你可能沒看文檔,或者忽略了。

.gitignore 官方文檔

Example to exclude everything except a specific directory foo/bar (note the /* - without the slash, the wildcard would also exclude everything within foo/bar):
$ cat .gitignore
    # exclude everything except directory foo/bar
    /*
    !/foo
    /foo/*
    !/foo/bar

知道了這個回到你的問題

node_modules/
// 排除這個文件夾。
!node_modules/@wang

但可能你已經(jīng)之前就把node_modules整體忽略了,導致現(xiàn)在加入排除文件,沒有效果。

這時再看下文檔。說可以參考:

SEE ALSO
git rm 官方文檔

看下來就可以發(fā)現(xiàn):

// -r 在給出前導目錄名時允許遞歸刪除。
// --cached 從緩存中刪除
git rm -r --cached node_modules/@wang
git status
// 查看狀態(tài)

這時你就會發(fā)現(xiàn) node_modules/@wang這個文件夾可以提交了。

如果覺得英文文檔有障礙,可以下載翻譯插件等工具,或者搜索查看中文文檔。

或者也可以通過搜索(不能科學上網(wǎng)的情況下,推薦必應(yīng)搜索),搜索git排除被忽略文件夾下的某個文件夾 等關(guān)鍵詞。

2017年1月13日 02:19
編輯回答
詆毀你

這里有個坑,翻了下百度,這篇文章可以解決你的問題

2018年2月4日 06:55