git - 带有 -a 的路径对 bash 函数没有意义

标签 git

这是我的 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/

相关文章:

git - SSH - 通过 CMD 拒绝权限(无法验证 git@github.com)

git - 在 git repo 中维护我的补丁

git - 在项目之间共享 Github pull 请求模板的最佳方式?

git - 如何确定 Git 中的 cherry-pick 的提交者?

Git - 在单个命令中提交和标记

git - 如何在两者之间拥有一个带有 pull 请求的公共(public)/私有(private) git 存储库

git - 在错误的 git 分支中工作

git push origin master 失败并给出错误 : src refspec HEAD does not match any

git - 使用 github api 的版本列表

eclipse - 是否可以在 Eclipse 的 EGit 中将暂存/未暂存视为树