从 git diff 中复制带有空格名称的文件
Copy files with spaced names from git diff
我想将文件从本地 git 复制到另一个目录,如下所示:
git diff --name-only tags/21.4.1 tags/21.4.2| xargs -0 -n 1 -Ifoo cp --parents foo /tmp/archive_build_dir/
cp -pv --parents $(git diff --name-only tags/21.4.1 tags/21.4.2) /tmp/archive_build_dir/
但即使我在 git diff
中添加双引号,它也不适用于名称中有空格的文件
更新:
只需将分隔符添加到 xargs:
git diff --name-only tags/21.4.1 tags/21.4.2| xargs -0 -n 1 -d "\n" -Ifoo cp --parents foo /tmp/archive_build_dir/
git diff
有一个 -z
option :
-z
When --raw, --numstat, --name-only or --name-status has been given, do not munge pathnames and use NULs as output field terminators.
Without this option, pathnames with "unusual" characters are quoted as explained for the configuration variable core.quotePath (see git-config[1]).
如果您想将其输出与 xargs -0 ...
合并,您应该使用此选项
我想将文件从本地 git 复制到另一个目录,如下所示:
git diff --name-only tags/21.4.1 tags/21.4.2| xargs -0 -n 1 -Ifoo cp --parents foo /tmp/archive_build_dir/
cp -pv --parents $(git diff --name-only tags/21.4.1 tags/21.4.2) /tmp/archive_build_dir/
但即使我在 git diff
中添加双引号,它也不适用于名称中有空格的文件更新:
只需将分隔符添加到 xargs:
git diff --name-only tags/21.4.1 tags/21.4.2| xargs -0 -n 1 -d "\n" -Ifoo cp --parents foo /tmp/archive_build_dir/
git diff
有一个 -z
option :
-z
When --raw, --numstat, --name-only or --name-status has been given, do not munge pathnames and use NULs as output field terminators.
Without this option, pathnames with "unusual" characters are quoted as explained for the configuration variable core.quotePath (see git-config[1]).
如果您想将其输出与 xargs -0 ...