git 命令的快捷方式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14753603/
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
Shortcuts for git commands
提问by Sam
I would like to use shortcuts or aliases for git commands.
我想为 git 命令使用快捷方式或别名。
git diff
git status
git push
git pull
git stash
git branch -a
How do I create shortcuts or aliases, is there a predefined list?
如何创建快捷方式或别名,是否有预定义列表?
回答by ogzd
Put this into your .gitconfig
把这个放进你的 .gitconfig
[alias]
st = status
ci = commit
br = branch
co = checkout
You can add as much as you want
您可以添加任意数量的
回答by Fred Foo
git config --global alias.<short> <long>
e.g.
例如
git config --global alias.cob "checkout -b"
(Without --global
, you get per-project aliases.)
(没有--global
,您将获得每个项目的别名。)
回答by Dimitris Baltas
I would recommend oh-my-zsh gitshortcuts.
我会推荐oh-my-zsh git快捷方式。
It has a very thorough (more than 100 shortcuts) list.
它有一个非常详尽的(超过 100 个快捷方式)列表。
Here is a smallsample to get you started:
这是一个小示例,可帮助您入门:
alias ga='git add'
alias gc='git commit -v'
alias gd='git diff'
alias gst='git status'
alias gco='git checkout'
alias gcm='git checkout master'
alias gb='git branch'
# view remote branches
alias gbr='git branch --remote'
alias gup='git pull --rebase'
alias gp='git push'
# push a newly created local branch to origin
alias gpsup='git push --set-upstream origin $(git_current_branch)'
The selection of letters in most shortcuts make them adequately intuitive.
大多数快捷方式中字母的选择使它们足够直观。
Using the shortcuts provided by a popular and active open source project has many benefits. Some of which:
使用流行且活跃的开源项目提供的快捷方式有很多好处。其中一些:
- never care if you lose them since you can easily find them!
- increases the chances of other people having the same shortcuts as you and thus learn from each other.
- decreases the chances of shortcuts conflicting with other commands.
- 如果您丢失它们,请不要在意,因为您可以轻松找到它们!
- 增加其他人与您拥有相同捷径的机会,从而相互学习。
- 减少快捷方式与其他命令冲突的机会。
Even if you don't use zsh, you can still copythem in a regular shell configuration file like .bashrc
.
即使你不使用 zsh,你仍然可以将它们复制到一个常规的 shell 配置文件中,比如.bashrc
.
I have also added
我也添加了
alias oh='less ~/.oh-my-zsh/plugins/git/git.plugin.zsh'
so that I can quickly read the available shortcuts right from the terminal.
这样我就可以直接从终端快速读取可用的快捷方式。
回答by Vlad
You can also add them to your .bashrc
to type even less.
您也可以将它们添加到您的输入中.bashrc
以减少输入。
See http://ozmm.org/posts/git_bash_aliases.htmlfor an example.
回答by parasrish
More than one way to do this. Explained below with examples:
不止一种方法可以做到这一点。下面举例说明:
[1] Using the "alias" option provided by the git itself.
[1] 使用 git 本身提供的“别名”选项。
Example:git config --global alias.co checkout
示例:git config --global alias.co checkout
Usage hence:git co
因此用法:git co
This is equivalent to making entries manually in the '~/.gitconfig'(this path since, --globalis used, otherwise the .gitconfigfile of the project, in which you attempting to set will be used).
这相当于手工制作中的条目“〜/的.gitconfig”(这条道路,因为,--global使用,否则的.gitconfig项目,在其中您尝试设置将被使用的文件)。
[alias]
co = checkout
Therefore, manually making entry to the file, as specified can also be another way of setting your aliases.
因此,按照指定手动输入文件也可以是设置别名的另一种方式。
[2] Using .bash_profile/.bashrc.
[2] 使用 .bash_profile/.bashrc。
Edit your ~/.bash_profileor ~/.bashrc, as below:
编辑您的~/.bash_profile或~/.bashrc,如下所示:
Example:alias go='git checkout'
示例:别名 go='git checkout'
Usage hence:go
用法因此:去
(Do not forget to 'source ~/.bash_profile' or 'source ~/.bashrc' after the changes to the file, based on your case).
(根据您的情况,在更改文件后不要忘记 'source ~/.bash_profile' 或 'source ~/.bashrc')。
So, if you clearly see, the second way is to further put the shorthand/aliases to the git-command usage (for your profile).
因此,如果您清楚地看到,第二种方法是进一步将速记/别名添加到 git-command 用法(用于您的个人资料)。
Also, the aliases meant for ease of usability, hence what you prefer/at ease, is what you can add (like: i can say probably, Giraffe = git checkout, if that is my ease).
此外,别名意味着易于使用,因此您更喜欢/放心,是您可以添加的(例如:我可以说,Giraffe = git checkout,如果这是我的方便的话)。
回答by Tredecies
I made a terminal "Mode" for bash called git_mode
in order to avoid typing git
and use c
for commit
and so forth.
我为庆典称为终端“模式” git_mode
,以避免打字git
和使用c
的commit
等等。
You can find it here.
你可以在这里找到它。
Sample commands look like:
示例命令如下所示:
# Add
alias a='git add'
alias add='git add'
# Diff
alias d='git diff'
alias diff='git diff'
# Grep/Search
alias search='git grep'
alias grep='git grep'
# Merge
alias merge='git merge'
alias m='git merge'
# Branch
alias b='git branch'
# Status
alias s='git status'
alias status='git status'
# Commit
alias c='git commit'
alias commit='git commit'
# Remote
alias remote='git remote'
# Pull
alias pull='git pull'
# Push
alias push='git push'
# init
alias init='git init'
alias i='git init'
# clone
alias clone='git clone'
# checkout
alias ch='git checkout'
alias checkout='git checkout'
# stash
alias stash='git stash'