Considering I have *.pdf
files in both my .gitignore
and .gitattributes
, how does git behave and prioritize between the two? Does it ignore pdf files or stores them as LFS?
.gitignore
ignores untracked files — those that haven't been added with git add
; .gitattributes
are for tracked files. That is, one PDF file could be processed with .gitattributes
and two other could be ignored (just an example).
.gitignore
tells git that by default it shouldn't pay attention to untracked files at a given path.
.gitattributes
tells git to modify how it performs certain operations (if/when it performs said operation) on files at a given path. For git to try to perform those operations usually you at least have to be trying to start tracking the file - and certainly that's the case with the attributes LFS uses.
In both cases, "at a given path" can also mean "matching a given pattern". So there is no conflict or prioritization; we just have to pay attention to what each of these means. If you put *.pdf
in .gitignore
, and also use .gitattributes
to set up *.pdf
with the attributes for LFS tracking, then:
By default, an untracked PDF file will be ignored by git.
To add a new PDF file to the index, you would override the ignore rule with git add -f
Once a PDF file exists at a specific path, that path is no longer governed by the ignore rule
Any PDF file you do add will be managed by LFS per the .gitattributes
Any PDF file already in the repo (which would be unaffected by the ignore rule) should be managed by LFS, though if it was committed before the .gitattributes
entry it may not be.
So in this setup, LFS is acting as a safety net to keep PDF files from blowing up your repo database even if someone overrides the ignore rule. Perhaps it means "there are one or two PDF files we really do track; but other PDF files could appear in the work tree, and we generally don't want them."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With