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

git st
git ci

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


当前回答

可以为git和非git命令设置别名。这看起来像是在1.5版中添加的。在我的Mac 2.5.4版本上,git配置帮助页面的一个片段显示:

如果别名展开以感叹号作为前缀,则它将被视为shell命令。

例如,在你的全局.gitconfig文件中,你可以有:

[alias]
    st = status
    hi = !echo 'hello'

然后运行它们:

$ git hi
hello
$ git st
On branch master

...

其他回答

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

如果你使用'!'操作符来生成一个shell:

aa = !git add -A && git status

这将添加所有文件,并为您提供$ git aa的状态报告。

为了方便地检查你的别名,添加这个别名:

alias = config --get-regexp ^alias\\.

然后一个快速的$ git别名会告诉你当前的别名以及它们的用途。

$ 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.

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

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

使用方法如下:

git dog

可以为git和非git命令设置别名。这看起来像是在1.5版中添加的。在我的Mac 2.5.4版本上,git配置帮助页面的一个片段显示:

如果别名展开以感叹号作为前缀,则它将被视为shell命令。

例如,在你的全局.gitconfig文件中,你可以有:

[alias]
    st = status
    hi = !echo 'hello'

然后运行它们:

$ git hi
hello
$ git st
On branch master

...