One way would be to force add the single file. Once tracked, git will continue tracking the file irrespective of whether it is ignored or not in any of your .gitignore
.
So simply using the below will work:
git add -f parent/child/child-02/file.txt
git commit -m "added file.txt"
If you really want to correct your .gitignore
file, you will have to add one more rule (!parent/child/child-02
). This essentially tells git
to not ignore the child-02
directory, and so the subsequent rules work:
parent/child/*
!parent/child/child-02
parent/child/child-02/*
!parent/child/child-02/file.txt
DEMO
test $ mkdir repo && cd repo && git init
repo $ mkdir -p parent/child/child-02
repo $ touch file parent/file parent/child/file parent/child/child-02/file.txt
repo $ cat .gitignore
parent/child/*
!parent/child/child-02
parent/child/child-02/*
!parent/child/child-02/file.txt
repo $ git add .
repo $ git status
new file: .gitignore
new file: file
new file: parent/child/child-02/file.txt
new file: parent/file