Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to gitignore snapshot folders?

I am starting to learn more about Jest and testing such as snapshot testing. The way I have my components in react configured is...

- src
  - components
    - Component1
      - index.js
      - __tests__
        - Component1.test.js
        - __snapshots__
  - Component2
      - index.js
      - __tests__
        - Component2.test.js
        - __snapshots__

and so on.

I'm wondering what would be the line to write in my .gitignore to ignore the __snapshots__ folder with this structure.

Currently I have this (which is wrong)

/src/components/*/__snapshots__/

Also, is it best to keep them in version control or to ignore them? I'd still like to know what I need to put in my gitignore, but would like to hear thoughts about this as well!

Thank you!

like image 846
kennycodes Avatar asked Nov 09 '18 17:11

kennycodes


People also ask

How do I ignore a folder in Git?

How to Ignore a File and Folder in Git. If you want to ignore only one specific file, you need to provide the full path to the file from the root of the project. If you want to ignore all files with a specific name, you need to write the literal name of the file.

What is Git ignore?

gitignore file is a text file that tells Git which files or folders to ignore in a project. A local . gitignore file is usually placed in the root directory of a project. You can also create a global . gitignore file and any entries in that file will be ignored in all of your Git repositories.

How do I add a file to Gitignore in Visual Studio?

Open Visual Studio and the solution needing an ignore file. From the top menu select Git > Settings. The above will open Visual Studio's Options with Source Control > Git Global Settings selected. From the list on the left select Git Repository Settings and then click the Add button for Ignore file.

Why. gitignore?

gitignore files. This file lists files that are intentionally untracked and should be ignored by Git. It is important to note that changes to files that were staged before being added to the . gitignore file will continue to be tracked by Git.


1 Answers

ignore the folder called snapshots anywhere, but not files with the same name

__snapshots__/

Since this has a “/” at the end only directories would be matched – removing it would also make the pattern catch files with the same name.

like image 146
victor zadorozhnyy Avatar answered Oct 08 '22 04:10

victor zadorozhnyy