我有一個腳本:
#!/bin/bash
git log -1 | grep -w '^commit' | cut -d ' ' -f2 | git show | grep -w '^index' | cut -d ' ' -f2 > tmp_out
while read -r arg
do
arg1=${arg[@]:0:10}
arg2=${arg[@]:23:10}
cmd="git diff ${arg1}^ ${arg2}"
echo $cmd
$cmd
done <tmp_out
理論上應該顯示在 git merge 期間發生的所有合并沖突。腳本給出錯誤:
git diff <SHA1>^ <SHA2>
error: object <SHA1> is a blob, not a commit
error: object <SHA1> is a blob, not a commit
fatal: ambiguous argument '<SHA1>^': unknown revision or path not in the working tree.
(SHA1 和 SHA2 是索引哈希)但是當我手動復制命令并運行時:
git diff <SHA1>^ <SHA2>
有用。所以我的問題是:為什么shell腳本不能執行git diff <SHA1>^ <SHA2>?
uj5u.com熱心網友回復:
解決辦法是徹底去除^。來自@torek 在評論中的回答。
#!/bin/bash
git show | grep -w '^index' | cut -d ' ' -f2 > tmp_out
while read -r arg
do
arg1=${arg[@]:0:10}
arg2=${arg[@]:23:10}
cmd="git diff ${arg1} ${arg2}"
echo $cmd
$cmd
done <tmp_out
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/471515.html
上一篇:bash中的決議串列
