Un-ignore /usr/lib/systemd/ in .gitignore with git repo on root filesystem
Actually, this is about un-ignoring any subdirectory that is grandchild to an ignored directory.
Running Linux Mint 22.2 (based upon Ubuntu 24.04), and having a git repository on root filesystem to keep track of the computer’s configuration, the vast majority of directories are ignored. One of the is /lib, however /lib/systemd/ should not be ignored, as it contains crucial files for the system’s configuration.
On other distributions, the relevant part in .gitignore usually goes:
[ ... ] bin/ boot/ dev/ home/ lib/* !lib/systemd/ lib64/ lib32/ libx32/ lost+found/ media/ mnt/ opt/ proc/ root/ run/ sbin/ [ ... ]
So lib/ isn’t ignored as a directory, but all its content, including subdirectories is. That allows for un-ignoring lib/systemd/ on the following row. That’s why lib/ isn’t ignore-listed like the other ones.
But on Linux Mint 22.2, /lib is a symbolic link to /usr/lib. And since git treats a symbolic link just like a file, /lib/systemd/ is treated as /usr/lib/systemd. Ignoring /lib as a directory has no effect, and un-ignoring /lib/systemd has no effect, because to git, this directory doesn’t even exist.
So go
$ man gitignore
and try to figure out what to do. It’s quite difficult actually, but it boils down to this:
usr/* !usr/lib/ usr/lib/* !usr/lib/systemd/
It’s a bit tangled, but the point is that /usr/lib is un-ignored, then all its files are ignored, and then /usr/lib/systemd is un-ignored.
The only good part about this solution is that it works.