Git 来自 shell 脚本的 diff 命令
Git diff command from shell script
我有一个脚本:
#!/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 合并期间发生的所有合并冲突。脚本出错:
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>
?
解决方案是完全删除 ^
。 @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
我有一个脚本:
#!/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 合并期间发生的所有合并冲突。脚本出错:
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>
?
解决方案是完全删除 ^
。 @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