我正在尝试为我的简单 git add/commit/push 创建一个带参数的别名。
我看到函数可以用作别名,所以我尝试了但没有成功。
之前我有:
alias gitall="git add . ; git commit -m 'update' ; git push"
但我希望能够修改我的提交:
function gitall() {
"git add ."
if [$1 != ""]
"git commit -m $1"
else
"git commit -m 'update'"
fi
"git push"
}
最佳答案
如果出于某种原因你真的需要使用带有参数的别名,你可以通过在你的别名中嵌入一个函数并立即执行它来破解它:
alias example='f() { echo Your arg was $1. };f'
我看到这种方法在 .gitconfig 别名中使用了很多。
关于shell - 带参数的 ZSH 别名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34340575/