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

git st
git ci

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


当前回答

我创建了别名dog来显示日志图:

git config --global alias.dog "log --all --decorate --oneline --graph"

使用方法如下:

git dog

其他回答

基本上,您只需要在~/.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命令甚至接受函数作为参数。看看别名。

我认为最有用的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 config alias。在Git存储库中执行以下命令:

git config alias.ci commit

对于全局别名:

git config --global alias.ci commit
$ 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.

在.gitconfig中包含多个别名文件

我建议使用.gitconfig include作为别名。一旦你开始创建别名,你可能最终会有很多。它们很可能是你想与他人分享的东西。把它们放在一个专用的文件中可以很容易地共享。您的团队甚至可以使用git回购来保存共享别名。当然还有一些你不想分享的别名,所以把它们保存在一个私人别名文件中。

[include]
    path=src/dotfiles/.gitaliases

[include]
    path=src/team-utils/gitaliases

[include]
    path=.gitaliases.private