Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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