.gitignore: track one file in an ignored directory
1 answer
One way would be to add one file. Once tracked, git will continue tracking the file regardless of whether it is ignored or not in any of yours .gitignore
.
So the simple usage below will work:
git add -f parent/child/child-02/file.txt
git commit -m "added file.txt"
If you really want to fix your file .gitignore
, you will need to add another rule ( !parent/child/child-02
). This essentially says git
not to ignore the directory child-02
, so the following 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
+6
source to share