我正在编写一个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所以这很好用--但是当我想使用git log时--通过xargs使用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,对吧?
发布于 2012-08-11 07:39:12
我会将您通过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"发布于 2012-08-11 03:23:29
问题是你在转义引号。我不知道为什么这是一个问题,但我试过了,问题肯定是转义的引号。不知何故,当xargs调用该命令时,它会将这些引号作为参数的一部分,所以不是搜索Always restore PG(magic_quote_gpc) on request shutdown,而是搜索"Always restore PG(magic_quote_gpc) on request shutdown"。以下内容应该适用于您:
svn log --xml --revision 323016 http://svn.php.net/repository | grep "<msg>" | sed 's/<msg>//' | xargs --verbose -i% git log --pretty=oneline --grep="%"https://stackoverflow.com/questions/11904468
复制相似问题