What I'm attempting to do is extract a list of 'projects' which have changed since a given commit. For this I'm approximating a project to a folder containing a changed file.

The problem I'm having is getting this to work with files which have spaces in their names:

$ git diff --name-only TREEISH.. | xargs -n 1 dirname

I've looked at the -0 option for xargs, and the -z option for diff, but this gives me:

$ git diff --name-only -z TREEISH.. | xargs -0 dirname
dirname: too many arguments

What am I missing?


Try this:

git diff --name-only -z TREEISH.. | while IFS= read -r n; do dirname "$n"; done 
  • IFS is the input field separator, needed to avoid trimming leading/trailing whitespace
  • -r is needed to avoid backslash processing.
  • The quotes around "$n" make it deal with spaces.

See here for more information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.