Home > Mobile >  How to ignore some files and directories using .gitgnore?
How to ignore some files and directories using .gitgnore?

Time:12-04

I have a directory structured like this:

main_folder
 .git
 .gitignore
 rootfolder
  .DS_Store
  folder1
   .ipynb_checkpoints/filename-checkpoint.csv
   abc.txt
   def.json
   somedir
    more.json
  folder2
   .DS_Store
   .ipynb_checkpoints/file-filename2-checkpoint.csv
   rty.csv
   somedir
    uis.py
    .ipynb_checkpoints/filename1-checkpoint.csv
    .DS_Store

Being in the main_folder, I would like to commit everything, except all folders and files having the DS_Store or ipynb_checkpoints substring.

In this specific case, I would like to commit:

main_folder
 rootfolder
  folder1
   abc.txt
   def.json
   somedir
    more.json
  folder2
   rty.csv
   somedir
    uis.py

In .gitignore-file, I have added:

**/checkpoint.csv
**/.DS_Store

But not all checkpoint files have being ignored. What command lines should I add into my .gitignore file located in main_folder-directory

CodePudding user response:

gitignore file has the functionality you need already built-in. You just need to have the name of the directory in the ignore file and git will ignore all files in that directory and all subdirectories:

checkpoint.csv
.DS_Store

If you want a file to be ignored just in the current directory, you can add "./{file}" to gitignore.

CodePudding user response:

It seems you should be ignoring any file if it's in a directory called .ipynb_checkpoints:

.DS_Store
.ipynb_checkpoints

Please note that the files inside .ipynb_checkpoints folders were previously added to git then you would have to remove them explicitely before ignore will work for them.


BTW. You may want to grab a community .gitignore for python development from https://github.com/github/gitignore/blob/main/Python.gitignore (it includes .ipynb_checkpoints :))

  • Related