当我运行以下命令时
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版本上失败了。
最后,为了证明xargs在运行git branch | grep solution- | cut -c 3- | xargs echo时得到了正确的参数,我得到了solution-1 solution-2 solution-3,这正是我所期望的。
发布于 2019-09-16 01:11:56
从你的问题,我得出结论,你有一个git回购与三个分支解决方案-1,解决-2和解决方案-3。
现在,当运行以下命令时
git checkout solution-1 && git checkout solution-2 && git checkout solution-3您得到了正确的输出,因为git签出每次都会获得一个有效的分支名称(它以不同的分支名称运行了3次)。
现在,让我们看看为什么在命令下运行时会出现错误,
git branch | grep solution- | cut -c 3- | xargs git checkout运行上述命令的相当于运行,
git checkout solution-1 solution-2 solution-3这将提示相同的错误。这是因为git签出只执行了一次,解决方案-1作为分支名称,解决方案2和解决方案-3作为文件名。
现在,您实际上希望为xargs的每个参数逐个切换分支。要做到这一点,您可以运行以下命令。
git branch | grep solution- | cut -c 3- | xargs -d '\n' -n1 git checkouthttps://stackoverflow.com/questions/57949163
复制相似问题