Git - Ignoring files with . gitignore

Asked

Viewed 348 times

2

Someone can explain to me clearly the difference between the use of the commands below in the file . gitignore ?

  • /pasta

  • pasta/

1 answer

9


You know you can put the .gitignore in any sub-folder of the project ? It took me a few years to figure that out, and I was happy with the discovery.

The first case, pasta/, does not require the folder to be in the same directory as the .gitignore. Could be any subdirectory called pasta which will be duly ignored.

The second case, /pasta/ force the directory to be ignored to be in the same folder as the .gitignore. So you can be very specific.

Imagine the following structure:

/--+
  |
  +- dira/ --+
   |         |
   |         +- .gitignore [1]
   |         +- subdira/ --+
   |         |              |
   |         |              +- pasta/
   |         +- pasta/
   |
   +- dirb/--+
   |         |
   |         +- .gitignore [2]
   |         +- subdirb/ --+
   |         |              |
   |         |              +- pasta/
   |         +- pasta/
   +- pasta/

The content of /dira/.gitignore (indicated by [1]) is:

pasta/

That of /dirb/.gitignore (indicated by [2]) is:

/pasta/

With this, the project will show the differences in the following directories pasta/:

  • /dirb/subdirb/pasta/
  • /pasta/

And ignore the following:

  • /dira/pasta/
  • /dira/subdira/pasta/
  • /dirb/pasta/
  • 1

    Thanks man, it was very clear your answer. It helped a lot!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.