带-a的路径对bash函数没有意义 [英] Paths with -a does not make sense for bash function

查看:36
本文介绍了带-a的路径对bash函数没有意义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的bash函数.

Here is my bash function.

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功能推送?

How to fix my bash function push?

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来添加参数,如

I just want to write a bash function push to add parameter,to run it such as

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" 括在引号中.

Looks like $1 is expanding into several arguments, and Git is taking the first one to be the commit message and the remainder as files. Guard "$1" into quotes.

但是我必须补充一点,该脚本存在一些问题.这是非常不安全的.您正在执行多个命令,而没有检查一次是否成功或输入是否正确.这样做并强制执行Git推送会在以后给您带来很大的头痛.

But I must add that there are several problems with that script. It's very unsafe. You are executing several commands without checking once for success or if the input is appropriate. Doing that and forcing a Git push can give you big headache later on.

这篇关于带-a的路径对bash函数没有意义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆