Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignoring .gitignore when running git archive

Tags:

git

I have a git repo with a bunch of source code, and when that compiles a bunch of binaries are produced. The binaries are all listed in appropriate .gitignore files, and not included in the repo.

However, I would like to distribute a source+binaries snapshot zipfile of my repo that contains all the binaries, but not things like the .git/ directory.

It would seem like the natural way to create a snapshot zipfile would be

git archive -o archive.zip 

But that doesn't include any of the binaries which are in .gitignore.

Ideas on how I can accomplish this with git archive? (My work-around is to manually create a zip archive that includes everything other than the .git/ directory)

like image 719
akeshet Avatar asked Apr 10 '12 23:04

akeshet


2 Answers

I don't think you are going to be able to use 'git archive' for what you hope to achieve. 'git archive' works on commits and your binary files simply won't be visible. Note 'git archive' is so commit centric that you can use git archive directly in a bare repository where no source controlled files exist explicitly.

like image 109
GoZoner Avatar answered Oct 22 '22 12:10

GoZoner


You can exclude files and/or directories from git archive by using the .gitattributes file.

  1. Create a file named .gitattributes in your project root (if it doesn't exist).
  2. Edit the file: Each exclusion should have a file pattern followed by "export-ignore":

    .gitattributes export-ignore
    .gitignore export-ignore
    /mytemp export-ignore
    
  3. Make sure to ignore the .gitattributes file itself!

  4. Make sure to commit the .gitattributes file, or git archive won't pick up the settings.

Then feel free to use your git archive -o archive.zip command, or variant.

Source here

like image 24
Fox. Avatar answered Oct 22 '22 13:10

Fox.