git diff --name-only and spaces

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


git archive -o $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.


Apologies, it was easy:

git archive -o $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!