In my git project, the file dir-name/file.txt
is not tracked by git, but I want it to be tracked.
- In
git status
the file is not listed in the tracked files and not in the untracked files.git add dir-name/file.txt
doesn’t make any effect. - In
git ls-files
, thedir-name
is listed, butdir-name/file.txt
doesn’t. git check-ignore -v dir-name/file.txt
doesn’t list anything.git submodule status
output:fatal: no submodule mapping found in .gitmodules for path 'dir-name'
How do I get git track this file? I suspect it has something to do with dir-name
was a submodule in the past, but I deleted the .submodules
file and dir-name/.git/
.
2
I suspect it has something to do with dir-name was a submodule in the past, but I deleted the
.submodules
file anddir-name/.git/
.
Yes, but those aren’t actually how Git tracks submodules. It is not through the .gitmodules
file – that’s only used to tell Git where to download the submodule from, and it’s possible to add submodules without creating any .gitmodules entry.
(Likewise, the dir-name/.git/
directory was only what caused Git to add dir-name
as a submodule entry in the beginning.)
Instead, the actual “submodule” marker is in the ‘tree’ (file list) itself: because it was originally added as a submodule, dir-name
is not being tracked as a subdirectory at all, it’s tracked as a third type of object.
You will need to fully remove the entry using git rm --cached dir-name
and then re-add it.