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

git st
git ci

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


当前回答

在~/中添加以下行。Gitconfig在您的主目录

[alias]
# one-line log
l = log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short
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

a = add
ap = add -p
c = commit --verbose
ca = commit -a --verbose
cm = commit -m
cam = commit -a -m
m = commit --amend --verbose

d = diff
ds = diff --stat
dc = diff --cached

s = status -s
co = checkout
cob = checkout -b
# list branches sorted by last modified
b = "!git for-each-ref --sort='-authordate' --format='%(authordate)%09%(objectname:short)%09%(refname)' refs/heads | sed -e 's-refs/heads/--'"

# list aliases
la = "!git config -l | grep alias | cut -c 7-"

一旦完成,你可以用git a代替git add。这同样适用于别名标题下的其他命令..

其他回答

windows的另一种可能是在一个目录中填满含有快捷方式的.bat文件。文件的名称就是要使用的快捷方式。只需将该目录添加到您的PATH环境变量中,您就可以在cmd窗口中使用所有的快捷方式。

例如(gc.bat):

git commit -m %1

在控制台中执行如下命令:

gc "changed stuff"

我添加这个作为答案的原因是,当使用这个时,你不局限于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.

以下是4个你可以用来节省时间的git快捷方式或别名。

打开命令行,键入下面的4个命令,然后使用快捷方式。

git config --global alias.co checkout  
git config --global alias.ci commit    
git config --global alias.st status    
git config --global alias.br branch  

现在测试一下吧!

$ git co              # use git co instead of git checkout
$ git ci              # use git ci instead of git commit
$ git st              # use git st instead of git status
$ git br              # use git br instead of git branch

一行设置

$ git config --global alias.co checkout && git config --global alias.br branch && git config --global alias.ci commit && git config --global alias.st status && git config --global alias.unstage 'reset HEAD --' && git config --global alias.last 'log -1 HEAD'

用法:

$ git st
$ git co
$ git br
$ git ci
$ git last
$ git unstage <file | dir>

一切都将变成:

$ cat ~/.gitconfig

[user]
    name = Sample User
    email = sample@gmail.com
[core]
    filemode = false
    compression = 1
    quotepath = off
    ignorecase = false
[color]
    ui = auto
[alias]
    co = checkout
    br = branch
    ci = commit
    st = status
    last = log -1 HEAD
    unstage = reset HEAD --

希望能快点。

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