Gitignore how to exclude a specific directory

I am trying to use a file .gitignoreto exclude a specific directory, but I have problems. I looked at how to do this in several forums, including stackoverflow, and although I found this a bit confusing, I thought I understood, but it doesn't seem to work as I thought.

So, I have a repo, and there is a specific directory at the top level called "images" that I want to exclude. Here is what I put into my .gitignorefile:

images/

I added and did everything, everything is good and good, he ignored the director of images at the top level. But then I realized that he also ignored forums / images. So what is the deal? How to handle ignoring a specific directory, but not any others with the same name?

+4
source share
2 answers

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

So you want:

/images

This will ignore any file OR directory with image names in the same directory as the gitignore file that you are using.

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

/images/
+7
source

Try changing images/to /images/on .gitignore docs

The leading slash corresponds to the beginning of the path. For example, "/*.c" matches "cat-file.c", but not "mozilla-sha1 / sha1.c".

+3
source

Source: https://habr.com/ru/post/1653948/


All Articles