-1

I have two lines in my .gitignore file:

somedir/local/*
!somedir/local/ssh/.gitkeep

However even the file .gitkeep in somedir/local/ssh seems to be ignored. which is evidently not what I wish. (I do wish all other files in somedir/local/ssh to be ignored).

If I don't use a nested directory but rather:

somedir/local/*
!somedir/local/.gitkeep

And put the file there it is working as expected.

I've also tried (ideal solution) to allow "gitkeep anywhere, never ignore any file named that way"

somedir/local/*
!.gitkeep

However this once again does not consider a file that is situated in a subdirectory that would be ignore (ie somedir/local/gitkeep) and only in the directly ignored directory.

paul23
  • 8,799
  • 12
  • 66
  • 149
  • Does [this](https://stackoverflow.com/a/44568924/4265352) answer your question? – axiac Jul 05 '23 at 17:48
  • Maybe your question is a general one, but as written it's kind of weird to *not* ignore just a single file name. If you know what it is, then either it's added already in which case the `.gitignore` is pointless, or you think it's going to be added in the future, in which case you can probably just add it now, even if it's just a blank file. – TTT Jul 05 '23 at 19:53
  • Well the idea of not ignoring .gitkeep is the ability to setup folder structures even in local only files. – paul23 Jul 05 '23 at 20:47

1 Answers1

1

This rules set should give the desired behavior:

somedir/local/**
!somedir/local/ssh
!somedir/local/settings
!.gitkeep

If you just want to maintain directory structure, instead I would recommend to have only one rule:

somedir/local/**

and commit every .gitkeep file forcefully:

find . -name '.gitkeep' | xargs git add -f
git commit
svlasov
  • 9,923
  • 2
  • 38
  • 39
  • I wish to also ignore everything under `somedir/local/ssh` *except* the file `.gitignore` - but there are many such directly like `ssh` – paul23 Jul 05 '23 at 18:14
  • You are contradicting yourself, in your original question you say you do not want `test` in `somedir/local/ssh` to be ignored. – svlasov Jul 05 '23 at 18:21
  • yes but I do want `abc` in `somedir/local/ssh` to be ignored. I also notice I wrote "test" in the text while I meant `.gitkeep`. Sorry if that confused people – paul23 Jul 05 '23 at 18:30
  • I updated the answer. – svlasov Jul 05 '23 at 18:41
  • is it possible to generalize this? IE I not only have `somedir/local/ssh` where I wish to keep `.gitkeep` but also `somedir/local/settings` and other directories. – paul23 Jul 05 '23 at 18:46
  • Yes, to some extent, see the update. You will need at least to list the directories which may contain `.gitkeep`. I would instead recommend to forcefully add/commit `.gitkeep` files and only keep one single rule `somedir/local/**`. – svlasov Jul 05 '23 at 19:00