我正在整理一个 bash 命令来查找旧 SVN 存储库中的 Git 提交。这是我的整个命令:
$ svn log --xml --revision 323016 http://svn.php.net/repository | grep "<msg>" | sed 's/<msg>//' | xargs --verbose -i% git log --pretty=oneline --grep=\"%\"
git log --pretty=oneline --grep="Always restore PG(magic_quote_gpc) on request shutdown"
运行命令的前几个部分会给出提交注释:
$ svn log --xml --revision 323016 http://svn.php.net/repository | grep "<msg>" | sed 's/<msg>//'
Always restore PG(magic_quote_gpc) on request shutdown
这样工作正常 - 但是当我想通过 xargs 使用 git log --grep 时,它不起作用(没有给我任何响应)。
这是奇怪的部分... --verbose
为我打印出命令。如果我复制并粘贴该确切的命令,我就会得到我需要的输出。即:
$ git log --pretty=oneline --grep="Always restore PG(magic_quote_gpc) on request shutdown"
87c038be06b8b0eb721270f98c858fd701f5d54b Always restore PG(magic_quote_gpc) on request shutdown
此外,由于某种原因这不起作用:
$ echo -n "Always restore PG(magic_quote_gpc) on request shutdown" | xargs --verbose -i% git log --grep=\"%\"
git log --grep="Always restore PG(magic_quote_gpc) on request shutdown"
所以这一定是我对 xargs 的使用,对吧?
最佳答案
我会将您通过 xargs 执行的命令包装到 sh
git rev-parse HEAD | xargs -n 1 -i{} sh -e "git log -1 {}"
我用它来解决一些转义问题以及为 xargs 传递的每个项目执行复杂的脚本:
git rev-parse HEAD | xargs -n 1 -i{} sh -e "some crazy looped code with {} embedded in multple places"
关于git - xargs 和 git log --grep,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11904468/