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
Git 如何在alias中设置函数参数?_Git_Bash_Github_Alias - Fatal编程技术网

Git 如何在alias中设置函数参数?

Git 如何在alias中设置函数参数?,git,bash,github,alias,Git,Bash,Github,Alias,下面是我的git推送wordpress目录的函数 pushwp(){ cd /var/www/html/wp git init git add * git commit -am "$1" git push -f origin master } pushwp功能状态良好 pushwp "it is a test" Reinitialized existing Git repository in /var/www/html/wp/.git/ On branch master nothing t

下面是我的git推送wordpress目录的函数

pushwp(){
cd /var/www/html/wp
git init
git add *
git commit -am  "$1"
git push -f origin master
}
pushwp功能状态良好

pushwp  "it is a test"
Reinitialized existing Git repository in /var/www/html/wp/.git/
On branch master
nothing to commit, working directory clean
Everything up-to-date
现在,使用别名分配函数

alias pushme='pushwp(){
cd /var/www/html/wp
git init
git add *
git commit -am  "$1"
git push -f origin master
}'
让我们试试看

pushme  "it is a test"
bash: syntax error near unexpected token `"it is a test"'

如何修复别名?

如前所述,您需要定义并调用别名。但你不需要在这里

确保不要每次推送repo时都初始化它:git init应该只执行一次,而不是该别名的一部分


您可以使用
git-add.
而不是
git-add*
(它依赖于bash扩展)

您已经有了一个函数,为什么要用别名来包装它呢?这毫无意义!只要使用这个函数。除非你想要一个git别名。你不需要。别名不是函数。别名只定义函数;它也不这么说。您可以让别名定义并调用函数(
alias pushme='pushwp(){…};pushwp'
),但正如@gniourf_gniourf所指出的,这样做的理由很少或根本没有。