.gitignore不会忽略目录

Hal*_*ton 60 git version-control github gitignore

我做了什么:

我认为github gui中有一些奇怪的配置导致了这个问题并阻止我从命令行甚至git-bash轻松使用git.

我最后只是卸载github和git然后重新安装git for windows.我现在让一切都在命令行上运行(除了我从git-bash运行的ssh).github gui更容易,更可靠.

感谢mu无论花时间试图弄明白这一点.我最终没有使用他的答案,但如果我不需要重新安装git,那将是我需要做的.


我在我的本地机器上使用github gui.我只是注意到我要做的提交是要更新我最近更新的所有节点模块.我设置我的.gitignore忽略整个node_modules/目录.

我不知道该怎么做.我在.gitignore中包含的所有文件类型都被忽略了.它只是它似乎忽略的目录.

这是我的.gitignore文件:

#################
## Sublime Text
#################

*.sublime-project
*.sublime-workspace

#################
## Images
#################

*.jpg
*.jpeg
*.png
*.gif
*.psd
*.ai

#################
## Windows detritus
#################

# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Mac crap
.DS_Store

#################
## Directories
#################

dev/
cms/core/config/
node_modules/
Run Code Online (Sandbox Code Playgroud)

mu *_*u 無 188

由于该node_modules目录已作为存储库的一部分进行跟踪,因此该.gitignore规则不适用于该目录.

你需要从git中解开目录

git rm -r --cached node_modules
git commit -m "removing node_modules"
Run Code Online (Sandbox Code Playgroud)

你可以运行上面的2 git-bash.

在此之后,.gitignore规则将忽略该目录.

请注意,node_modules一旦您提取更改,这将从您的其他存储库中删除该目录.只有您进行该提交的原始存储库仍将具有该node_modules文件夹.


Mat*_*w M 16

如果已跟踪.gitignore文件,则文件不会覆盖此文件.你需要使用git rm --cached <files>

查看全部细节git rmhttps://www.kernel.org/pub/software/scm/git/docs/git-rm.html 我就遇到了这个一次或两次,我早早就使用Git,这是不完全是我预期要么.

  • 如果我们忽略OP问题中的拼写错误问题,这是对相关标题的更全面的回答。对于通过搜索到达的人很有用。 (2认同)

Sco*_*NET 9

与Zach相似,我也使用echo "node_modules/" >> .gitignore

问题在于它已经使用encoding创建了文件UCS-2 LE BOM。使用notepad ++,我将编码更改为UTF-8和voila-现在忽略了node_modules。

在此处输入图片说明


pro*_*sti 5

如果您使用节点项目,我喜欢这样.gitignore

# See http://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
node_modules

# testing
coverage

# production
build

# misc
.DS_Store
.env
npm-debug.log
Run Code Online (Sandbox Code Playgroud)