.bashrc 在未经我同意的情况下运行别名:致命:不是 git 存储库(或任何父目录):.git

cod*_*321 2 bash git ubuntu .bash-profile macos

我在 bash_profile 中有这个,我已经将罪魁祸首缩小到:

alias initialpush="git push -u origin `git symbolic-ref --short -q HEAD`"
Run Code Online (Sandbox Code Playgroud)

我无法正确获取 bash_profile:

cchilders:~ 
$ src
fatal: Not a git repository (or any of the parent directories): .git
Run Code Online (Sandbox Code Playgroud)

更改为其他样式无济于事,同样的问题:

alias initialpush="git push -u origin $(git symbolic-ref --short -q HEAD)"
Run Code Online (Sandbox Code Playgroud)

我认为这只会发生在 Mac 上,我不能确定,直到我回家检查。我的脚本是在 Ubuntu 上编写的。在我使用 Mac 之前,我不记得发生过这个错误。我怎样才能阻止这个 bash_profile 发疯?谢谢

use*_*686 5

特定的子命令样式没有任何区别 - 无论哪种方式,只要它们在双引号内,它们就会在解释 'alias' 行时展开。为避免这种情况,请将别名命令放在单引号中,或者至少用反斜杠转义$`符号。

alias initialpush='git push -u origin $(git symbolic-ref --short -q HEAD)'