0

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

Frank R.
  • 2,328
  • 1
  • 24
  • 44
  • If this temporary source directory is also a git repository, you could fetch the tag with `--depth=1` from any repository which holds the tag. – ElpieKay Nov 08 '21 at 09:43
  • You could create a detached working tree in a temporary directory with: `git worktree add -d ../temp tagname` – Richard Smith Nov 08 '21 at 10:06
  • Does this answer your question? [Do a "git export" (like "svn export")?](https://stackoverflow.com/questions/160608/do-a-git-export-like-svn-export) – Joe Nov 08 '21 at 10:36

3 Answers3

1

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

Alecto Irene Perez
  • 10,321
  • 23
  • 46
  • 1
    Thanks. The directory is deleted each time and is exported to from different repositories so using `git pull` does not quite work for my scenario, but I have use `git clone ${repository_path} --branch TAG` and that is much faster than doing the zip and unzip. – Frank R. Nov 08 '21 at 12:54
0

Here are two possible ways :

LeGEC
  • 46,477
  • 5
  • 57
  • 104
0

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.

Alex Jasmin
  • 39,094
  • 7
  • 77
  • 67
  • Thanks. I ended up using `git clone` just for the sake of performance even though I can't quite use it as Alectro suggested it. – Frank R. Nov 08 '21 at 12:52