Mac OS X Yosemite v.10.10.5.
I am trying to use the cp
command to copy one Git directory to another.
cp -r /path/to/dir/from/ /path/to/dir/to/
Returns this error:
cp: /path/to/dir/to/.git/objects/00/00ad2afeb304e18870d4509efc89fedcb3f128: Permission denied
This error is returned one time each for (what I believe, but haven't verified, is) every file in the directory.
The first time I ran the command it worked properly, as expected, without error. But, without making any changes to any files, the second (and subsequent) times I ran the command, I got the error.
What's going on? And how can I fix this?
Edit:
In response to a question in the comment:
What does
ls -l /path/to/dir/to/.git/objects/00/00ad2afeb304e18870d4509efc89fedcb3f128
show?
The answer is it shows:
-r--r--r-- 1 myusername staff 6151 May 6 00:45 /path/to/dir/to/.git/objects/00/00ad2afeb304e18870d4509efc89fedcb3f128
The reason you are getting Permission Denied
is because you are trying to overwrite a file that already exists in the destination directory that has read only permissions set on it. Since it appears you're trying to overwrite it you could just remove the destination directory if it exists before the copy operation. Also you should use -R
, not -r
...
Historic versions of the cp utility had a -r option. This implementation supports that option; however, its use is strongly discouraged, as it does not correctly copy special files, symbolic links, or fifo's.
Using a command such as this should resolve your issue:
[[ ! -d dest ]] || rm -rf dest ; cp -R src dest
The above checks if dest
exists; if it does recursively remove it, then copy the source
to dest
,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With