Tarballing without Git metadata

zaf picture zaf · Jun 18, 2010 · Viewed 36.9k times · Source

My source tree contains several directories which are using Git source control, and I need to tarball the whole tree excluding any references to the Git metadata or custom log files.

I thought I'd have a go using a combination of find/egrep/xargs/tar, but somehow the tar file contains the .git directories and the *.log files.

This is what I have:

find -type f . | egrep -v '\.git|\.log' | xargs tar rvf ~/app.tar

Can someone explain my misunderstanding here? Why is tar processing the files that find and egrep are filtering?

I'm open to other techniques as well.

Answer

Ole Tange picture Ole Tange · Jun 18, 2010

You will get a nasty surprise when the number of files increase to more than one xargs command: Then you will first make a tar file of the first files and then overwrite the same tar file with the rest of the files.

GNU tar has the --exclude option which will solve this issue:

tar cvf ~/app.tar --exclude .git --exclude "*.log" .