Make git ignore generated files

后端 未结 3 1879

I have several projects that have a large number of files that, when processed, generate other files. There is no need to track the generated files, in fact, in some cases you

3条回答
  •  悲哀的现实
    2021-01-22 14:26

    Several simple solutions:

    • Add all suffixes (e.g. .pdf) to .gitignore as *.pdf, and git add -f those version-this-one.pdf that should be versioned, git will keep track of those (need a bit of care). The *.pdf is really a glob, so you could exclude, say, PDFs whose hames start with uppercase by [A-Z]*.pdf.
    • As above, but add e.g. *.pdf for all PDFs, and !version-this-one.pdf to exclude one from the excluded set (can also use a pattern here)
    • Make a complete list of the generated files into .gitignore. Need to keep it up to date (not too bad, if a new one shows up, git will consider it untracked, just add it then).
    • Mix and match: Use the above methods as you want for different filename patterns
    • Per directory .gitignore: git searches first in this directory's .gitignore, if not found in the parent's, ... As you can exclude patterns with !, this stops a search there.

    Check out gitignore(5).

提交回复
热议问题