Strange artifacts when using git archive

87 Views Asked by At

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

git archive [email protected]: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?

1

There are 1 best solutions below

1
phd On BEST ANSWER

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 [email protected]:path/to/repo.git HEAD dir1/dir2/MyFile.xml | tar xvf -