我看了一段录像,里面有人
git st
git ci
去工作。当我这样做时,我得到一个错误,问我是否我指的是其他东西。 作为一个新手,我想知道你要怎么做才能完成这件事?
我看了一段录像,里面有人
git st
git ci
去工作。当我这样做时,我得到一个错误,问我是否我指的是其他东西。 作为一个新手,我想知道你要怎么做才能完成这件事?
当前回答
对于那些希望以git别名执行shell命令的人,例如:
$ git pof
在我的终端将推动当前分支到我的原点回购:
[alias]
pof = !git push origin -f $(git branch | grep \\* | cut -d ' ' -f2)
在哪里
$(git branch | grep \\* | cut -d ' ' -f2)
命令返回当前分支。
这是手动输入分支名称的快捷方式:
git push origin -f <current-branch>
其他回答
在~/中添加以下行。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。这同样适用于别名标题下的其他命令..
这招对我很管用:
bco = "!f(){ git branch ${1} && git checkout ${1}; };f"
on:
$ git --version
git version 1.7.7.5 (Apple Git-26)
如果您想要~/。Gitconfig选项,可以更深入地挖掘,另一个选项是通过将它们包装在全局节点包中来编写完全自定义的git命令。
在你的包裹里。Json,您将定义根命令(例如:gt),然后筛选特定的命令以执行正确的git命令。例如,git checkout my-branch可以是gt co mybranch。
npm上的“christian-git”包使用这个方法:https://github.com/alexmacarthur/christian-git
以下是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
如果你使用'!'操作符来生成一个shell:
aa = !git add -A && git status
这将添加所有文件,并为您提供$ git aa的状态报告。
为了方便地检查你的别名,添加这个别名:
alias = config --get-regexp ^alias\\.
然后一个快速的$ git别名会告诉你当前的别名以及它们的用途。