Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
“运行”;git过滤器分支“;来自bashshell_Bash_Git - Fatal编程技术网

“运行”;git过滤器分支“;来自bashshell

“运行”;git过滤器分支“;来自bashshell,bash,git,Bash,Git,我似乎无法让“git过滤器分支”在bash中工作: 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

我似乎无法让“git过滤器分支”在bash中工作:

  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 b62178fd4d40e1e52a7bfef64ff2f269c3aff7f8 "Mon Aug 12 13:03:00 2019"
Rewrite b62178fd4d40e1e52a7bfef64ff2f269c3aff7f8 (8/8) (0 seconds passed, remaining 0 predicted)    
WARNING: Ref 'refs/heads/master' is unchanged

在bash中,如果我只是键入它,而不使用fix\u commit\u date,它就可以正常工作。有没有办法让fix\u commit\u date bash命令正常工作?谢谢。

您的shell函数使用了不适当的引用

尝试在
git filter branch
前面加上
echo

echo git filter-branch --env-filter \
  'if [ $GIT_COMMIT = b62178fd4d40e1e52a7bfef64ff2f269c3aff7f8 ]
  then
    export GIT_AUTHOR_DATE="Mon Aug 12 13:03:00 2019"
    export GIT_COMMITTER_DATE="Mon Aug 12 13:03:00 2019"
  fi' -
观察输出。对于提交哈希ID的测试,您看到了什么

然后尝试编写的shell函数,再次在
git
前面插入
echo

fix_commit_date() { 
   echo 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 b62178fd4d40e1e52a7bfef64ff2f269c3aff7f8 "Mon Aug 12 13:03:00 2019"
你看到了什么输出

这里的技巧是扩展参数
$1
$2
,但仍然将整个表达式作为单个单词提供给命令。有很多方法可以做到这一点;这里有一个:

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
}
首先插入
echo
尝试此变体


顺便提一下,我最喜欢的一个技巧是将shell变量设置为包含双引号:

DQ='"'
echo "John told me to say ${DQ}hello${DQ}"
每个shell扩展元字符都可以放在一个变量中:

DOL='$'
BQ='`'
SQ="'"  # not technically needed
否则也可以设置“不可见”字符:

TAB=$'\t'
NL=$'\n'
现在,您可以编写以下内容:

echo "This has some ${DOL}weird ${BQ}ch${TAB}ara${NL}cters in it, doesn't it?"

你说的“我只是把它打出来”到底是什么意思?实际的命令是什么?git filter branch--env filter\'如果[$git_COMMIT=b62178fd4d40e1e52a7fef64ff2f269c3aff7f8],则导出git_AUTHOR_DATE=“Mon Aug 12 13:03:00 2019”导出git_提交者_DATE=“Mon Aug 12 13:03:00 2019”fi'-fp可能的重复。非常感谢echo调试提示!