Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .