0

I'm currently trying to retrieve a single file from a GitLab Repo with the following command (I'm on Windows):

git archive --remote=git@git.myrepo.de:path/to/repo.git HEAD dir1/dir2/MyFile.xml > MyFile.xml

Essentially it works, but there are some strange artifacts in front and after the actual content of the file. This is how the command prompt shows them:

The XML version tag at the bottom of the image is the start of the actual file content. Does anyone have an idea how to get rid of this?

TigersEye120
  • 664
  • 1
  • 9
  • 28

1 Answers1

3

git archive creates tar archives even for 1 file. And that's exactly what you see at the screen — a content of a tar archive. Perhaps you ran the command without redirection or tried to cat MyFile.xml which is not an XML but a tar file.

To clear the screen run clear. To extract files from the archive use tar:

git archive --remote=git@git.myrepo.de:path/to/repo.git HEAD dir1/dir2/MyFile.xml | tar xvf -
phd
  • 82,685
  • 13
  • 120
  • 165
  • 1
    Also since you're specifically downloading from a gitlab repo, [there's an API to get the raw file contents straight from gitlab](https://docs.gitlab.com/ee/api/repository_files.html#get-raw-file-from-repository), it's not necessary to go through the `git archive` dance if you don't want to support arbitrary git repositories. – Masklinn Jan 28 '20 at 14:33