我正在尝试做这样的事情:
> function gitb(){ git checkout -b $1; alias $1='git checkout $1'; }
> gitb sample
Switched to a new branch 'sample'
> git checkout master
Switched to branch 'master'
> sample
Switched to branch 'sample'
但是,函数gitb的行为不符合预期,因为:
> alias sample
alias sample='git checkout $1'
而不是
> alias sample
alias sample='git checkout sample'
有人能告诉我如何实现我的目标吗?
答案 0 :(得分:2)
了解单引号和双引号之间的区别。
function gitb() { git checkout -b $1; alias $1="git checkout $1"; }