1

I added this to my .gitignore file:

# JPEG
*.jpg
*.jpeg
*.jpe
*.jif
*.jfif
*.jfi

# JPEG 2000
*.jp2
*.j2k
*.jpf
*.jpx
*.jpm
*.mj2

# JPEG XR
*.jxr
*.hdp
*.wdp

# Graphics Interchange Format
*.gif

# RAW
*.raw

# Web P
*.webp

# Portable Network Graphics
*.png

# Animated Portable Network Graphics
*.apng

# Multiple-image Network Graphics
*.mng

# Tagged Image File Format
*.tiff
*.tif

# Scalable Vector Graphics
*.svg
*.svgz

# Portable Document Format
*.pdf

# X BitMap
*.xbm

# BMP
*.bmp
*.dib

# ICO
*.ico

# 3D Images
*.3dm
*.max

Found here.

Then I added some .png files and commited this change and pushed it, but the files are showing up if I execute git status.

    geändert:       skin/frontend/venedor/custom/images/kreis_rot_weiss.png
    geändert:       skin/frontend/venedor/custom/images/kreis_weiss.png

What am I doing wrong?

Black
  • 18,150
  • 39
  • 158
  • 271

1 Answers1

2

I think these files were in the staging area before I made my changes to the gitignore file. I executed git reset --hard HEAD and added my png files again and now they don't appear if I call git status

So .gitignore will only apply to new files and not to files already in the staging area.

Black
  • 18,150
  • 39
  • 158
  • 271
  • 2
    More precisely, listing a file in `.gitignore` has no effect if the file is *tracked*. A file is tracked if and only if it is in the index *right now*. Having done `git add` earlier, it *was* in the index. Doing `git reset --hard HEAD` made the index match the `HEAD` commit; it was not in the `HEAD` commit, so now it was not in the index. – torek Apr 08 '19 at 15:57
  • 2
    The index is also called the "staging area", so your answer is correct. However I think some people think of the "staging area" as the part of the index that *does not match* the `HEAD` commit. *All* the files are in the staging area, it's just that usually *most* of them match the `HEAD` commit so that Git says nothing about them. – torek Apr 08 '19 at 15:57
  • 2
    The other thing I like to show those new to the idea of the index / staging-area / cache in Git is that `git ls-files --stage` actually displays the entire contents of the staging area. This is the only way to see *directly* what's in it! In a big repository, this produces a huge amount of output, which is why `git status` shows what's in it by *comparing* to the `HEAD` commit instead of showing everything. – torek Apr 08 '19 at 16:00
  • Nice insight @torek! – Niloct Apr 08 '19 at 16:19