gitgit-archive

Strange artifacts when using git archive


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?


Solution

  • 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 -