这是我的 bash 函数。
push() {
> cd /var/www/html/wp
> git init
> git add *
> git commit -am $1
> git push -f origin master
> }
我要执行它。
debian8@hwy:$push 'to delete file test'
Reinitialized existing Git repository in /var/www/html/wp/.git/
fatal: Paths with -a does not make sense.
如何修复我的 bash 函数推送?
rm/var/www/html/wp/test后可以成功执行以下命令
cd /var/www/html/wp
git init
git add *
git commit -am 'to delete file test'
git push -f origin master
我只想写一个 bash 函数 push 来添加参数,运行它,例如
push 'to delete file test'
让推送功能为
push(){
cd /var/www/html/wp
git init
git add *
git commit -am $1
git push -f origin master
}
最佳答案
看起来 $1
正在扩展为多个参数,Git 将第一个作为提交消息,其余作为文件。保护 "$1"
到引号中。
但我必须补充一点,该脚本存在几个问题。这是非常不安全的。您正在执行多个命令,而没有检查一次是否成功或输入是否合适。这样做并强制执行 Git 推送会让您日后非常头疼。
关于git - 带有 -a 的路径对 bash 函数没有意义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41416200/