Github对全局git配置有以下建议~/.gitconfig:
[alias] # Is this [-] only a comment in .gitconfig?
gb = git branch
gba = git branch -a
gc = git commit -v
gd = git diff | mate
gl = git pull
gp = git push
gst = git status
Run Code Online (Sandbox Code Playgroud)
上面的命令在我的旧Git中有效.但是,由于某些未知原因,它们现在不起作用.
问题似乎不在命令中.它可能在另一个git相关文件中控制哪个文件影响别名.
你怎么能让别名起作用?
hax*_*ney 13
首先要注意的是git别名仅在你调用git时才适用,因此别名st = status将在你运行时生效:
$ git st
Run Code Online (Sandbox Code Playgroud)
如果你想做到:
$ gst
Run Code Online (Sandbox Code Playgroud)
要运行,git status您需要为bash(或您使用的任何shell)设置别名.
好吧,对于只是简单版本的git命令的别名(比如stfor status),你不需要git为它添加前缀.此外,如果要执行shell命令而不是git子命令,则必须在别名定义前添加一个感叹号,如中所述git-config(1).我的别名部分~/.gitconfig看起来像这样:
[alias]
st = status
ci = commit -s
br = branch
co = checkout
vis = !gitk --all &
Run Code Online (Sandbox Code Playgroud)
然后我可以运行:
$ git st # Runs "git status"
$ git ci # Runs "git commit -s"
$ git vis # runs "gitk --all &"
Run Code Online (Sandbox Code Playgroud)
等等.
我相信GitHub所指的是系统别名,而不是'.gitconfig'别名.
在其他方面,你需要的类型,比如这里所示,下面的Unix命令,使这些"别名"工作:
alias g=’git’
alias gb=’git branch’
alias gba=’git branch -a’
alias gc=’git commit -v’
alias gca=’git commit -v -a’
alias gd=’git diff | mate’
alias gl=’git pull’
alias gp=’git push’
Run Code Online (Sandbox Code Playgroud)