Running shell command with git filter-branch

时间:2019-06-01 14:03:08

标签: bash git shell sh

I'm trying to build an application that change git commit history timestamp with git filter-branch. But I am getting wrong timestamp when I execute following shell script and check git commit history with "git log". Am I doing wrong with using function argument? Any help?



fix_commit_date() { 
    git filter-branch --env-filter \
    "if [ $GIT_COMMIT =  $(1) ]
     then
         export GIT_AUTHOR_DATE=\"$(2)\"
         export GIT_COMMITTER_DATE=\"$(2)\"
     fi" -f
}
fix_commit_date c1f456c87bd66cad07b24827946df5a44cac95f2 "Tue Mar 3 21:38:53 2009 -0800"

1 个答案:

答案 0 :(得分:2)

以下语法旨在评估子外壳中的代码并捕获输出:

$(code here)

以下语法捕获了一些解除位置参数引用的方法(有关更多信息,请参见sh(1)

$1
${1}

因此,您看到错误的结果,因为您试图运行并捕获命令12的输出,这些输出很可能不存在。

切换到第二种语法之一。并宁愿双引号两个扩展。