2012-08-10 156 views
2

我在一個bash命令中查找來自舊SVN存儲庫的Git提交。這裏是我的整個命令:xargs和git log --grep

$ 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登錄--grep通過xargs,它不起作用(不給我答覆)。

這是奇怪的部分... --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使用,對不對?

回答

2

我想包你通過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" 
0

問題是您正在逃避報價。我不知道爲什麼這是一個問題,但我試過了,問題肯定與逃脫的引號有關。不知何故,當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="%"