tags:

views:

49

answers:

1
+1  Q: 

git-archive vs. cp

What is the advantage of using

git archive master/foo | tar -x -C ~/destination

to deploy a copy of /foo vs. just copying from the the working copy with

cp foo ~/destination/foo

So, unless for some reason you don't want to copy everything over from that sub directory foo in master (or whatever branch you happening to be working on), using cp for deploying to a [destination] would suffice.

+2  A: 

git archive only exports items that are part of the git repository. cp copies everything that's under the specified directory, including the .git directory, files which are ignored by git, etc.

jamessan
I partly agree with the first part. But there's only one .git folder and it's outside of foo so copying foo will not mean that .git folder get's copied... only foo and it's sub-folders.
DKinzer
Also if I've added everything in foo to the previous commit (why wouldn't I) that means foo is exactly like the copy on master branch.
DKinzer
You might not want *everything* in foo to be copied: think intermediate build products, editor backup files and anything else that is commonly in your .gitignore file.
Cameron Skinner
@Cameron Skinner, I guess that's really the determining factor here. If I don't want to copy everything from foo. Then using git-archive makes a lot more sense. But otherwise cp is just as good.
DKinzer
@DKinzer: The vast majority of projects have at least something in their `.gitignore`, be it build products, logs, temporary files, local data, whatever. I'd say it's much more common to want to avoid those files, but you're right, if you don't care if they come along, just copy.
Jefromi
[`git archive`](http://www.kernel.org/pub/software/scm/git/docs/git-archive.html) also respects `export-ignore` and `export-subst` [gitattributes](http://www.kernel.org/pub/software/scm/git/docs/gitattributes.html), and if given commit ID or tag ID it stores commit ID in a global extended pax header (unless requested to not do that).
Jakub Narębski