bash 将 git 别名添加到 .bash_profile 不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12676864/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adding git alias to .bash_profile not working
提问by Marius Pop
I edited my $Home .bash_profile to include some git alias commands. I am rather new to this and I can't figure out what went wrong.
我编辑了我的 $Home .bash_profile 以包含一些 git 别名命令。我对此很陌生,我无法弄清楚出了什么问题。
.bash_profile
.bash_profile
alias gs='git status '
alias ga='git add '
alias gb='git branch '
alias gc='git commit'
alias gd='git diff'
alias go='git checkout '
alias gk='gitk --all&'
alias gx='gitx --all'
alias got='git '
alias get='git '
PS1="\u$ "
alias ll="ls -lahG"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && \
. "$HOME/.rvm/scripts/rvm"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && \
. "$HOME/.rvm/scripts/rvm"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && \
. "$HOME/.rvm/scripts/rvm"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && \
. "$HOME/.rvm/scripts/rvm"
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && \
. "$HOME/.rvm/scripts/rvm"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && \
. "$HOME/.rvm/scripts/rvm"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function
I can't seem to understand what I did wrong. Any ideas?
我似乎无法理解我做错了什么。有任何想法吗?
[EDIT]Just wanted to mention that the part that I added is from PS1 up. For example alias ll = "ls -lahG"works well. The ones above do not.
[编辑]只想提一下,我添加的部分是从 PS1 开始的。例如alias ll = "ls -lahG"效果很好。上面的没有。
[EDIT2]I tried to user gs(){ git status "$*"; } instead but that didn't seem to do the trick.
[EDIT2]我试图用户 gs(){ git status "$*"; 相反,但这似乎并没有奏效。
[EDIT3]The problem was that I had to source ~/.profile. What I ended up doing is putting it in the ~/.bashrc file and source that file at Sputnick's recommendation.
[EDIT3]问题是我必须源 ~/.profile。我最终做的是将它放在 ~/.bashrc 文件中,并在 Sputnick 的推荐下获取该文件。
回答by Gilles Quenot
You should use ~/.bashrcand not~/.bash_profilefor aliases.
您应该使用~/.bashrcand 而不是~/.bash_profile别名。
~/.bashrcis for interactive use, see http://mywiki.wooledge.org/DotFiles& http://wiki.bash-hackers.org/scripting/bashbehaviour
~/.bashrc用于交互式使用,请参阅http://mywiki.wooledge.org/DotFiles& http://wiki.bash-hackers.org/scripting/bashbehaviour
And most important thing, you should source the modified file with :
最重要的是,您应该使用以下内容获取修改后的文件:
. ~/.bashrc
or
或者
source ~/.bashrc

