Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: How to ignore/specify files for *checkout*

Tags:

git

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?

like image 368
ian Avatar asked Mar 31 '11 02:03

ian


1 Answers

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.gz

Create 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-ignore

Files 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.

like image 101
Cascabel Avatar answered Sep 26 '22 01:09

Cascabel