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

git st
git ci

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


当前回答

如果您想要~/。Gitconfig选项,可以更深入地挖掘,另一个选项是通过将它们包装在全局节点包中来编写完全自定义的git命令。

在你的包裹里。Json,您将定义根命令(例如:gt),然后筛选特定的命令以执行正确的git命令。例如,git checkout my-branch可以是gt co mybranch。

npm上的“christian-git”包使用这个方法:https://github.com/alexmacarthur/christian-git

其他回答

需要执行命令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中添加行即可

[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命令。

在你的包裹里。Json,您将定义根命令(例如:gt),然后筛选特定的命令以执行正确的git命令。例如,git checkout my-branch可以是gt co mybranch。

npm上的“christian-git”包使用这个方法:https://github.com/alexmacarthur/christian-git

这里给出了别名。即使这里有很好的答案,我加上这个是因为 它在Windows和Linux中有所不同