Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.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
Bash 如何使用git别名和shell函数来构建提交消息_Bash_Git_Shell - Fatal编程技术网

Bash 如何使用git别名和shell函数来构建提交消息

Bash 如何使用git别名和shell函数来构建提交消息,bash,git,shell,Bash,Git,Shell,我正在尝试创建一个git别名,以自动化我的PR合并和批准 完整的git命令如下所示: git签出主机&&git sync&&git merge--no ff-m'合并到hotfix/X-3144(拉取请求#1112)'remotes/origin/hotfix/X-3144 其中X是问题的比特桶前缀。在阅读其他堆栈溢出问题时,我得出以下结论: mergeto = "!f() { git checkout $1 && git sync && git merge --

我正在尝试创建一个git别名,以自动化我的PR合并和批准

完整的git命令如下所示:

git签出主机&&git sync&&git merge--no ff-m'合并到hotfix/X-3144(拉取请求#1112)'remotes/origin/hotfix/X-3144

其中X是问题的比特桶前缀。在阅读其他堆栈溢出问题时,我得出以下结论:

mergeto = "!f() { git checkout $1 && git sync && git merge --no-ff -m 'Merged in {$2}/B2B-{$3} (pull request #{$4})' remotes/origin/$2/X-$3;}; f "
所以,我很自然地用它来合并一个有冲突的公关。解决这些冲突后,我发出一个
git commit
,git会用我之前键入的commit消息显示nano。我的目标是使用我的参数构造提交消息。例如,如果我使用:

git合并到主修补程序123 1120

我的最后一条提交消息应该是“合并到hotfix/X-123(拉请求#1120)”但我得到的却是“合并到{$2}/X-{$3}(拉请求{$4})”

我如何以这样的方式指定参数,使其能够正常工作

我读了一些关于如何在git别名中使用shell函数的stack over flow帖子,但找不到使用参数转义文本的示例。

使用和建议,我通过转义双引号来实现:

mergeto = "!f() { git checkout $1 && git sync && git merge --no-ff -m \"Merged in $2/B2B-$3 (pull request #$4)\" remotes/origin/$2/X-$3;}; f "

谢谢你的帮助

这是因为您希望使用变量展开,但使用单引号。这是站不住脚的,因为参数替换不会发生在单引号中。将它们改为双引号,并用反斜杠转义,你应该会很好。