views:

26

answers:

5

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

+1  A: 

Is git-archive what you're looking for?

Skilldrick
Probably not. Since it's multiple gits in the source tree.
zaf
+1  A: 

You could do that without grep. find is powerful

 find . -type f -not \( -iname ".git" -or -iname ".log" \) | xargs ...
SchlaWiener
The problem was my find parameters. See my answer. Thanks for the alternative.
zaf
A: 

Try something like this:

git archive --format=tar -o ~/tarball.tar -v HEAD

Add your .log files and everything else you don't want to be packed to your .gitignore file.

jkramer
A: 

[slap] Bah! The parameters to find were in the wrong order! Didn't see the warnings because they whizzed off the screen. This allowed '.' to pass thru egrep which caused tar to slurp up everything.

That will teach me for drowning important messages in verbose debug.

This works:

find . -type f | egrep -v '\.git|\.log' | xargs tar cvf ~/app.tar
zaf
+2  A: 

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" .
Ole Tange
Nice - thanks!!
zaf
Even better would be to quote the '*.log', so that if you do happen to have related files in the current working directory, the shell won't expand it.
Arafangion