Frank R.
Frank R.

Reputation: 2380

alternative to git archive for exporting

I have been using git for ages but there are some things that just don't click for me.

As part of my normal build system, I need to export a specific tag into a temporary source directory and the only way I've found to do this is by using git archive.

Specifically:

/Applications/Xcode.app/Contents/Developer/usr/bin/git archive #{internal_version} --format=zip > #{$temp_source_code_path}/code.zip

This is stupid as I first need to zip the entire thing and then unzip it before building it.

The actual git repository is local and the command is run from it.

Is there a better (faster) way of doing this?

Best regards,

Frank

Upvotes: 0

Views: 700

Answers (3)

Alex Jasmin
Alex Jasmin

Reputation: 39506

If you want to export files from git without creating an intermediate archive, you can pipe the data through tar directly:

git archive master | tar xC /some/path

If you want to be able to perform git operations in the directory where the files are exported, consider using git clone or git worktree instead.

Upvotes: 0

LeGEC
LeGEC

Reputation: 52066

Here are two possible ways :

Upvotes: 0

Alecto
Alecto

Reputation: 10750

You can clone a local repository just like you would a remote one:

git clone /path/to/your/repo /path/to/build/dir

Then, whenever you need to build, you can run

cd /path/to/build/dir
git pull
# Run build script

This has the added benefit that it'll only copy over changes, rather than archiving the entire repository.

That being said, rsync might be a more appropriate tool

Upvotes: 1

Related Questions