我看了一段录像,里面有人

git st
git ci

去工作。当我这样做时,我得到一个错误,问我是否我指的是其他东西。 作为一个新手,我想知道你要怎么做才能完成这件事?


当前回答

这招对我很管用:

bco = "!f(){ git branch ${1} && git checkout ${1}; };f"

on:

$ git --version

git version 1.7.7.5 (Apple Git-26)

其他回答

我在用户目录(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

我的.gitconfig文件的PFA截图

使用以下别名

[alias]
    cb = checkout branch
    pullb = pull main branch

这将为status创建一个别名st:

Git配置——添加别名。圣的地位

我认为最有用的gitconfig是这样的,我们总是在git中使用20%的函数,你可以试试“g ll”,它是惊人的,细节:

[user]
    name = my name
    email = me@example.com
[core]  
    editor = vi 
[alias]
    aa = add --all
    bv = branch -vv
    ba = branch -ra
    bd = branch -d
    ca = commit --amend
    cb = checkout -b
    cm = commit -a --amend -C HEAD
    ci = commit -a -v
    co = checkout
    di = diff
    ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --numstat
    ld = log --pretty=format:"%C(yellow)%h\\ %C(green)%ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short --graph
    ls = log --pretty=format:"%C(green)%h\\ %C(yellow)[%ad]%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=relative
    mm = merge --no-ff
    st = status --short --branch
    tg = tag -a 
    pu = push --tags
    un = reset --hard HEAD  
    uh = reset --hard HEAD^
   [color]  
    diff = auto  
    status = auto  
    branch = auto 
   [branch]  
    autosetuprebase = always

为了让别名比其他答案中提到的标准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以及第二个参数。