0

I use a results directory for storing data generated by my code. This data I do not wish to keep in the repo, so I ignore all files with the extensions the data uses (.csv, .txt).

Unfortunately, git does not track empty directories. A solution, as presented here, is to stick a .gitignore file in the directory. This works well. However....

I often want to clean out the directory to not confuse old results with new. Often, I will rename the old one and make a new one with the old name. (e.g., now I will have the directorys results_old and an empty results).

The problem is that now the .gitignore file is missing from the results directory and I need to manually add it back.

Is there any utility that can be used to 'replace' the .gitignore or enforce that it is 'recreated' in that directory?

Top level .gitignore contents:

*.csv
*.txt
*.text
__pycache__
Community
  • 1
  • 1
Ulad Kasach
  • 11,558
  • 11
  • 61
  • 87
  • Can you post your .gitignore file (the top one, don't put one in the results directory)? Also, why are you tracking the results directory if it just contains data output that you want to ignore? – Steve Harris Mar 29 '17 at 23:15
  • @SteveHarris Tracking the directory so that an error does not occur if the directory does not exist. The script could check for it, but I was wondering if there was another way. – Ulad Kasach Mar 30 '17 at 19:05
  • I think the directory should be considered a runtime or build artifact and handle it that way. Much easier to maintain, as you are seeing. – Steve Harris Mar 31 '17 at 16:51

1 Answers1

2

Your setup should create the directory if not exists, perhaps during application initialization. That is easier than deleting and figuring out way of recreating it. You can still ignore the entire path by single line and don't have to think about the directory at all.

hurturk
  • 5,214
  • 24
  • 41