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

git st
git ci

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


当前回答

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

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

[include]
    path=src/dotfiles/.gitaliases

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

[include]
    path=.gitaliases.private

其他回答

这招对我很管用:

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

on:

$ git --version

git version 1.7.7.5 (Apple Git-26)

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

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

一行设置

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

希望能快点。

在~/中添加以下行。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。这同样适用于别名标题下的其他命令..

我的.gitconfig文件的PFA截图

使用以下别名

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