.gitignore - 忽略图像文件不起作用

.gitignore - ignoring image files not working

我有这个 .gitignore 文件:

.DS_Store
node_modules
/dist
screen

# local env files
.env.local
.env.*.local

# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

# Vue Browser Extension Output
*.pem
*.pub
*.zip
/artifacts

我正在尝试添加一条规则,告诉 git 忽略 .jpeg.jpg.code-workspace 文件,但添加的规则是当我在线推送存储库并且这些文件无论如何都会被复制时被忽略。这个语法正确吗?

# Ignoring psd and image files
*.jpg
*.psd
# Ignoring VS workspace files
*.code-workspace

我怀疑您可能需要包含其他格式,请查看此 ,特别是在 printf '*.jpg\n*.jpeg\n*.png\n*.gif\n' >> .gitignore 行。

在你的情况下,你可以添加到你的 .gitignore

*.jpg
*.jpeg
*.png
*.gif
*.tiff

.gitignore 中的语法看起来不错。

您的存储库如何:.jpg.jepg 文件是否已推送到存储库?如果文件已保留在存储库中(git push 已执行),您必须取消跟踪此文件。然后在推送文件后 Git 将跟踪此添加的文件,并且将跳过任何跳过的匹配规则。

使用以下命令,您可以从存储库中删除文件而无需物理删除:

git rm --cache folder/to/the/imagefiles

提交更改后,所有文件都将从存储库中删除,忽略应该可以正常工作。

git rm 文档。