我看了一段录像,里面有人
git st
git ci
去工作。当我这样做时,我得到一个错误,问我是否我指的是其他东西。 作为一个新手,我想知道你要怎么做才能完成这件事?
我看了一段录像,里面有人
git st
git ci
去工作。当我这样做时,我得到一个错误,问我是否我指的是其他东西。 作为一个新手,我想知道你要怎么做才能完成这件事?
当前回答
我在用户目录(vim ~/.profile)的.profile中添加了所有的alias命令。
alias gs='git status'
alias gp='git pull'
alias gph='git push'
alias gd='git diff | mate'
alias gau='git add --update'
alias gc='git commit -m'
alias gca='git commit -v -a'
alias gb='git branch'
alias gba='git branch -a'
alias gco='git checkout'
alias gcob='git checkout -b'
alias gcot='git checkout -t'
alias gcotb='git checkout --track -b'
alias glog='git log'
alias glogp='git log --pretty=format:"%h %s" --graph'
alias gfo='git fetch origin'
然后,我在bash和zsh shell中添加了source命令。
在bash shell (vim ~/.bashrc)中
source ~/.profile
在zsh shell中(vim~/)。zshrc)
source ~/.profile
其他回答
这里给出了别名。即使这里有很好的答案,我加上这个是因为 它在Windows和Linux中有所不同
你可以使用git的配置设置自定义的git别名。语法如下:
git config --global alias.<aliasName> "<git command>"
例如,如果你需要一个别名来显示有合并冲突的文件列表,运行:
git config --global alias.conflicts "diff --name-only --diff-filter=U"
现在你只能使用"conflicts"来使用上面的命令:
git conflicts
# same as running: git diff --name-only --diff-filter=U
基本上,您只需要在~/.gitconfig中添加行即可
[alias]
st = status
ci = commit -v
或者你可以使用git config alias命令:
$ git config --global alias.st status
在unix中,如果别名中有空格,则使用单引号:
$ git config --global alias.ci 'commit -v'
在windows中,如果别名有空格或命令行参数,则使用双引号:
c:\dev> git config --global alias.ci "commit -v"
alias命令甚至接受函数作为参数。看看别名。
为了让别名比其他答案中提到的标准git配置方式更短,我创建了一个npm包mingit (npm install -g mingit),这样大多数命令将变成两个字符而不是两个单词。下面是一些例子:
g a . // git add .
g b other-branch // git branch other-branch
g c "made some changes" // git commit -m "made some changes"
g co master // git checkout master
g d // git diff
g f // git fetch
g i // git init
g m hotfix // git merge hotfix
g pll // git pull
g psh // git push
g s // git status
其他命令也同样简短。这也保持了bash的完成。该包为您的dotfiles添加了一个bash函数,适用于osx, linux和windows。此外,与其他别名不同,它别名git -> g以及第二个参数。
$ git update git: 'update' is not a git command. See 'git --help'. Did you mean this? update-ref $ git config --global alias.update 'pull -v' $ git update From git://git.kernel.org/pub/scm/git/git = [up to date] html -> origin/html = [up to date] maint -> origin/maint = [up to date] man -> origin/man = [up to date] master -> origin/master = [up to date] next -> origin/next = [up to date] pu -> origin/pu = [up to date] todo -> origin/todo Already up-to-date.