具有 git 的 xargs 检出失败并出现路径规范错误
xargs with git checkout fails with pathspec error
当我运行下面的命令
git branch | grep solution- | cut -c 3- | xargs git checkout
我得到这个错误输出
error: pathspec 'solution-2' did not match any file(s) known to git.
error: pathspec 'solution-3' did not match any file(s) known to git.
当我运行下面的命令
git checkout solution-1 && git checkout solution-2 && git checkout solution-3
我得到了这个正确的输出
Switched to branch 'solution-1'
Your branch is ahead of 'master' by 1 commit.
(use "git push" to publish your local commits)
Switched to branch 'solution-2'
Your branch is ahead of 'master' by 1 commit.
(use "git push" to publish your local commits)
Switched to branch 'solution-3'
Your branch is ahead of 'master' by 3 commits.
(use "git push" to publish your local commits)
我不明白为什么 git 在 xargs 版本上失败。
最后,只是为了证明如果我 运行 git branch | grep solution- | cut -c 3- | xargs echo
我得到 solution-1 solution-2 solution-3
,xargs 得到了正确的参数,这正是我所期望的。
根据您的问题,我得出的结论是您有一个包含 3 b运行ches solution-1、solution-2 和 solution-3 的 git 存储库。
现在当你运行下面的命令
git checkout solution-1 && git checkout solution-2 && git checkout solution-3
你得到正确的输出,因为 git 结帐每次都得到一个有效的 b运行ch 名称(运行 3 次使用不同的 b运行ch 名称) .
现在,让我们看看为什么在 运行ning 下面的命令
时出现错误
git branch | grep solution- | cut -c 3- | xargs git checkout
运行上面的命令相当于运行ning,
git checkout solution-1 solution-2 solution-3
这将提示您 同样的错误。这是因为 git checkout 仅执行一次,其中 solution-1 作为 b运行ch 名称,solution-2 & solution-3 作为文件名。
现在,您实际上想要为 xargs 的每个参数一个一个地切换 b运行ches。为此,您可以 运行 以下命令。
git branch | grep solution- | cut -c 3- | xargs -d '\n' -n1 git checkout
当我运行下面的命令
git branch | grep solution- | cut -c 3- | xargs git checkout
我得到这个错误输出
error: pathspec 'solution-2' did not match any file(s) known to git.
error: pathspec 'solution-3' did not match any file(s) known to git.
当我运行下面的命令
git checkout solution-1 && git checkout solution-2 && git checkout solution-3
我得到了这个正确的输出
Switched to branch 'solution-1'
Your branch is ahead of 'master' by 1 commit.
(use "git push" to publish your local commits)
Switched to branch 'solution-2'
Your branch is ahead of 'master' by 1 commit.
(use "git push" to publish your local commits)
Switched to branch 'solution-3'
Your branch is ahead of 'master' by 3 commits.
(use "git push" to publish your local commits)
我不明白为什么 git 在 xargs 版本上失败。
最后,只是为了证明如果我 运行 git branch | grep solution- | cut -c 3- | xargs echo
我得到 solution-1 solution-2 solution-3
,xargs 得到了正确的参数,这正是我所期望的。
根据您的问题,我得出的结论是您有一个包含 3 b运行ches solution-1、solution-2 和 solution-3 的 git 存储库。
现在当你运行下面的命令
git checkout solution-1 && git checkout solution-2 && git checkout solution-3
你得到正确的输出,因为 git 结帐每次都得到一个有效的 b运行ch 名称(运行 3 次使用不同的 b运行ch 名称) .
现在,让我们看看为什么在 运行ning 下面的命令
时出现错误git branch | grep solution- | cut -c 3- | xargs git checkout
运行上面的命令相当于运行ning,
git checkout solution-1 solution-2 solution-3
这将提示您 同样的错误。这是因为 git checkout 仅执行一次,其中 solution-1 作为 b运行ch 名称,solution-2 & solution-3 作为文件名。
现在,您实际上想要为 xargs 的每个参数一个一个地切换 b运行ches。为此,您可以 运行 以下命令。
git branch | grep solution- | cut -c 3- | xargs -d '\n' -n1 git checkout