I've got a unix-shell script that's supposed to work on nix machines. This doesn't run on OS X however, due to "cp" command not defined. Changing it to "copy" didn't help.

git log -1 --pretty=format:"%h" | xargs -I %id% git diff-tree --no-commit-id --name-only -r %id% | xargs -I % cp --parents % upd/

The script should make a copy of files changed in last git commit.

  • I'm wondering if it has more to do with the percentage sign than with cp. Because cp should be available in any case, it's such a basic command. – cello May 17 '15 at 18:21
  • 2
    or "cp" on OS X doesn't know the --parents option – cello May 17 '15 at 18:23
  • If you have Command Line Tools for Xcode installed you can download GNU core utilities and install the GNU version of cp which works with --parents. I just tested it and it works nice. – user3439894 May 17 '15 at 19:43

Have a look at this SO thread: https://stackoverflow.com/questions/11246070/cp-parents-option-on-mac

cp is available on OS X, but it does not support the --parents option, as I guessed. Instead of using cp --parents, replace it with ditto as mentioned in the SO answer.

  • Thanks, I will look at it and possibly reply with a solution. – Nick Volynkin May 17 '15 at 18:27

You must log in to answer this question.

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