通过 xargs util 将配置参数传递给 git 命令
Pass configuration parameter(s) to a git command via xargs util
我正在尝试使用 xargs
构建命令以传递配置参数:user.name
和 user.email
到 git commit
。
由 xargs
构建的命令:
git -c user.name=abc -c user.email=abc@mail.com commit
我尝试过的:
echo "-c user.name=abc -c user.email=abc@mail.com" | xargs -I % git % commit
但是,git
returns 这个:
unknown option: -c user.name=abc -c user.email=abc@mail.com
即使 xargs
冗长,命令也能正常工作。
echo "-c user.name=abc -c user.email=abc@mail.com" | xargs -tI % git % commit
这会打印要执行的命令 git -c user.name=abc -c user.email=abc@mail.com commit
,当复制粘贴到终端时该命令有效。
请注意,配置参数由空格分隔。
Some context for what exactly I am trying to do by passing configuration parameters
根据评论,xargs
将单个参数 %
替换为单个参数 -c user.name=abc -c user.email=abc@mail.com
;结果命令
git -c user.name=abc -c user.email=abc@mail.com commit
有两个参数,第一个是-c user.name=abc -c user.email=abc@mail.com
,显然是无效选项。
我能想到的最便携的解决方法是 shell 重新解释该行:
echo "-c user.name=abc -c user.email=abc@mail.com" | xargs -I % bash -c "git % commit"
这样,xargs
将使用两个参数执行 bash
:-c
和 git -c user.name=abc -c user.email=abc@mail.com commit
。 bash -c command
执行该命令,其中包括 bash
通常执行的完整命令行解析。这将导致 bash
使用五个参数执行 git
:-c
、user.name=abc
、-c
、user.email=abc@mail.com
和 commit
。 =29=]
我正在尝试使用 xargs
构建命令以传递配置参数:user.name
和 user.email
到 git commit
。
由 xargs
构建的命令:
git -c user.name=abc -c user.email=abc@mail.com commit
我尝试过的:
echo "-c user.name=abc -c user.email=abc@mail.com" | xargs -I % git % commit
但是,git
returns 这个:
unknown option: -c user.name=abc -c user.email=abc@mail.com
即使 xargs
冗长,命令也能正常工作。
echo "-c user.name=abc -c user.email=abc@mail.com" | xargs -tI % git % commit
这会打印要执行的命令 git -c user.name=abc -c user.email=abc@mail.com commit
,当复制粘贴到终端时该命令有效。
请注意,配置参数由空格分隔。
Some context for what exactly I am trying to do by passing configuration parameters
根据评论,xargs
将单个参数 %
替换为单个参数 -c user.name=abc -c user.email=abc@mail.com
;结果命令
git -c user.name=abc -c user.email=abc@mail.com commit
有两个参数,第一个是-c user.name=abc -c user.email=abc@mail.com
,显然是无效选项。
我能想到的最便携的解决方法是 shell 重新解释该行:
echo "-c user.name=abc -c user.email=abc@mail.com" | xargs -I % bash -c "git % commit"
这样,xargs
将使用两个参数执行 bash
:-c
和 git -c user.name=abc -c user.email=abc@mail.com commit
。 bash -c command
执行该命令,其中包括 bash
通常执行的完整命令行解析。这将导致 bash
使用五个参数执行 git
:-c
、user.name=abc
、-c
、user.email=abc@mail.com
和 commit
。 =29=]