1

I have this .gitignore file:

.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

I'm trying to add a rule that will tell to git to ignore the .jpeg or .jpg and .code-workspace files, but the added rules added are ignored when I push the repository online and these files are anyway copied. Is this syntax correct?

# Ignoring psd and image files
*.jpg
*.psd
# Ignoring VS workspace files
*.code-workspace
nukiko12
  • 129
  • 1
  • 1
  • 10

2 Answers2

3

The syntax in .gitignore looks good.

What about your repository: are the.jpg and .jepg files pushed to the repository? If the files stay already in the repository (git push already executed), you must untrack this file. Then after push the file Git will tracked this added files and any skipping matching rules will be skipped.

With following command you can removes the file from the repository without physically deleting:

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

After committing that change, all files will be removed from the repository, and ignoring should work properly.

git rm documentation.

SwissCodeMen
  • 4,222
  • 8
  • 24
  • 34
  • no, the files are't pushed to the repository at the moment, I'm facing this problem with some repository that I need to push. So you suggest me to untrack that files? – nukiko12 Aug 21 '20 at 22:52
  • 1
    if your repository isn't pushed, then you must just untracked your file, when you've already done `git add` or `git commit`. If you are not sure, untrack the files, nothing can happen, you don't deleting the files physical, only the files from the repository! – SwissCodeMen Aug 22 '20 at 20:57
1

I suspect you might need to include additional formats, have a look at this link specifically at this printf '*.jpg\n*.jpeg\n*.png\n*.gif\n' >> .gitignore line.

In your case you can just add to your .gitignore

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

eorochena
  • 176
  • 12