0

I have a directory in the format: ~/models/*/*, where the second * represents 220 directories named hmm0 to hmm220.

I only want to include the last directory in the commit, which I have managed to do with the .gitignore file using a sequence of ! and ignore lines (this already works):

!models/
models/*
!models/*/
models/*/*
!models/*/hmm220/

However, the issue is that the number of directories can change. For example, I may have 240 directories the next time named from hmm0 to hmm240. I want to always only take the last directory (and ignore previous ones). Is this possible, and if so how? If not, is there a better solution than just having to change the .gitignore file each time the number of directories change?

  • Could you split it into models/archive and models/current and implement a logic, that moves current to archive upon a new model? – FloLie Dec 29 '20 at 16:28
  • Do these directories contain files generated by the project? You should not keep them in the same repository as the code (or you should not keep them in the repository at all). – axiac Dec 30 '20 at 12:46

1 Answers1

0

I would readjust the models directory, so to keep the important one in current and don't sync the archives.

In your code you would then implement something like(not working BASH ;) ):

archive_count=`ls -l | grep "^d" | wc -l`
mkdir /models/archive/hm$archive_count
mv  /models/current/* /models/archive/hm$archive_count/
models
    |-archive
        |-hm0
        |-hm1
    |-current
        |-current files

.gitignore
!/models/archive
/models/archive/*```
FloLie
  • 1,820
  • 1
  • 7
  • 19