gitignore, how to exclude a specific directory

20,076

Solution 1

You want to set the root to / which will be relative to the location of your gitignore file.

So you want:

/images

That will ignore any file OR directory named images in the same directory as the gitignore file you are using.

If you want to specify that it should only match the images directory then add the trailing slash:

/images/

Solution 2

Try changing images/ to /images/ per the .gitignore docs

A leading slash matches the beginning of the pathname. For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".

Share:
20,076
Whitewind617
Author by

Whitewind617

Updated on July 22, 2022

Comments

  • Whitewind617
    Whitewind617 almost 2 years

    I'm trying to utilize a .gitignore file to exclude a specific directory, but I'm having some trouble. I looked up how to do this previously on a few forums, including stackoverflow, and while I found it a bit confusing, I had thought I understood it, but it seems to not be working as I thought.

    So I have a repo here, and there's a specific directory in the top level called "images" that I want to exclude. Here's what I put in my .gitignore file:

    images/
    

    I added and committed everything, all well and good, it ignored the images director in the top level. But then I realized it also ignored forums/images. So what's the deal? How do I handle ignoring a specific directory, but not any others with the same name?