git diff --name-only and spaces

I had to recover the set of files modified during a specific commit as follows:

COMMIT=28cd71c36323b8ff4ff01cfabed0a1764d4744c3

git archive -o changed.zip $COMMIT $(git diff --name-only $COMMIT $COMMIT^)

If there are spaces in file names the above does not work.

The question is, how can deal correctly with spaces in names returned by git diff. There are several options involving sed/xargs, but I would like to have a feedback from you experts.

Thanks

Apologies, it was easy:

git archive -o changed.zip $COMMIT $(git diff --name-only $COMMIT $COMMIT^ | sed ‘s/.*/"&"/’)

Hi @eruffaldi,

Thank you for sharing your solution! We’re looking forward to seeing you around!

Best,

Andrea