If I don't want .html files tracked I can add the pattern to .gitignore and they'll be ignored. I'd like to know how I can do the converse - at checkout, how could I ask git to only checkout certain types of files or not checkout certain types of files?
For example, if I didn't want html files I could write:
git checkout HEAD . --no .html
if that existed. Is there a way already built in, or do I just have to run something else post-checkout?
If you want to package up files for deployment, you probably don't need - or want - the repo itself. This is exactly what git archive is for. A couple examples from the manpage (linked):
git archive --format=tar --prefix=junk/ HEAD | (cd /var/tmp/ && tar xf -)Create a tar archive that contains the contents of the latest commit on the current branch, and extract it in the /var/tmp/junk directory.
git archive --format=tar --prefix=git-1.4.0/ v1.4.0 | gzip > git-1.4.0.tar.gzCreate a compressed tarball for v1.4.0 release.
You ought to be able to get it to do exactly what you want, with the help of the export-ignore attribute:
export-ignoreFiles and directories with the attribute export-ignore won’t be added to archive files. See gitattributes(5) for details.
For example, to exclude the directory private and the files mine.txt and secret.c, you could put in the file .gitattributes:
private/ export-ignore
secret.c export-ignore
Just like gitignore files, you can put those anywhere in your repository, and they'll operate from that directory, but starting from the top level is a good bet.
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