How do I qualify paths in the .gitignore file w.r.t. the repo root directory?
From: Brent Goodrick <hidden>
Date: 2016-06-15 22:46:16
Say I have these files and directories [2]:
/home/smart_tator/misc_files/.gitignore
/home/smart_tator/misc_files/foo/
/home/smart_tator/misc_files/bar/
/home/smart_tator/misc_files/bar/baz/foo/
/home/smart_tator/misc_files/bar/baz/real/
then I do:
cd /home/smart_tator/misc_files/; git init
and say I have this line in that .gitignore file:
foo/
And then I naively execute:
git add bar/
then the bar/baz/real/ is added, but these are dutifully ignored:
/home/smart_tator/misc_files/foo/
/home/smart_tator/misc_files/bar/baz/foo/
But consider in my real repo, I have thousands of files, versus the
Tinker Toy example shown above. And consider that I don't know about
that bar/baz/foo/ exists ahead of time, because I'm not the only
developer checking in content to the repo that might contain precious
"foo/"'s to keep. I can't move my top level foo/, as I have tools that
rely upon that foo/ being in its place.
That means that we can't solve this problem efficiently/effectively
with the negation operator in the .gitignore file:
foo/
!bar/baz/foo/
because sooner or later someone is going to get surprised as to why
their foo/ isn't being added in some other subdirectory, and they will
"fix it" by committing a change where they have removed the foo/ from
the .gitignore file, thus causing the top level foo/ to show up as
candidates for addition in git status output.
Is there some way to express that the foo/ that is to be ignored is
always the one in /home/smart_tator/misc_files/ directory, but all
other foo/ subdirectories in any other directory under consideration
should still continue to participate in adds and merges, all without
having to "over-express" the exceptions with negation operators?
Maybe the imaginary .gitignore syntax I am thinking of would be one of
the following (most of these are just silly/fun):
</>foo/ # <-- Huh?
<top>foo/ # <-- What the ...?
//foo/ # <-- Smells like Perforce or Windows UNC paths
/foo/ # <-- No! Matches UNIX root filesystem directory paths!
>foo/ # <-- You can't have a > character in DOS or Unix paths, can you?
$root/foo/ # <-- I like this syntax the best [1]
Thanks,
bg
[1] Maybe there are other "variables" besides $root that might be
useful to be added in the future, like $HOME.
[2] By "repo root directory", I mean whatever "$GIT_DIR/.." resolves to.