Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git archive including the actual repository?

I need to create an archive of my Git project, ignoring and leaving out files specified by .gitignore, but including the actual .git repository folder. Simply running git archive master leaves out the .git folder.

Is there a way to make git archive include the .git folder but still ignore files specified by .gitignore?

like image 490
Naftuli Kay Avatar asked Jul 23 '12 22:07

Naftuli Kay


2 Answers

Since git archive just produces a tar archive you can work on that file with tar directly.

$ git archive HEAD > tar.tar
$ tar -rf tar.tar .git

tar's -r option appends the files given to the archive being worked on (specified after -f). Check tar's man page for the intimidating list of features tar has.

like image 77
Benjamin Bannier Avatar answered Nov 09 '22 11:11

Benjamin Bannier


Looks like doing something like

# copy over all project files except for those ignored
git clone /path/to/repository /path/to/output 
# create a tar.gz archive of the project location
tar czvf projectExport.tar.gz /path/to/output
# remove the cloned directory
rm -fr /path/to/output

gets the job done. It's not the most beautiful solution in the world, but it looks like it works.

like image 32
Naftuli Kay Avatar answered Nov 09 '22 11:11

Naftuli Kay