我看到有人收到的截屏视频
git st
git ci
Run Code Online (Sandbox Code Playgroud)
上班.当我这样做时,我得到一个错误,问我是否有其他意思.
作为一个git newb,我需要知道你要做什么来完成这项工作?
Die*_*ias 928
基本上你只需要添加行 ~/.gitconfig
[alias]
st = status
ci = commit -v
Run Code Online (Sandbox Code Playgroud)
或者您可以使用git config alias命令:
$ git config --global alias.st status
Run Code Online (Sandbox Code Playgroud)
在unix上,如果别名有空格,请使用单引号:
$ git config --global alias.ci 'commit -v'
Run Code Online (Sandbox Code Playgroud)
在Windows上,如果别名有空格或命令行参数,请使用双引号:
c:\dev> git config --global alias.ci "commit -v"
Run Code Online (Sandbox Code Playgroud)
alias命令甚至接受函数作为参数.看看别名.
Mat*_*kin 167
正如其他人所说,添加git别名的适当方法.gitconfig
是通过编辑~/.gitconfig
或使用git config --global alias.<alias> <git-command>
命令在全局文件中
下面是我的~/.gitconfig
文件的别名部分的副本:
[alias]
st = status
ci = commit
co = checkout
br = branch
unstage = reset HEAD --
last = log -1 HEAD
Run Code Online (Sandbox Code Playgroud)
另外,如果您正在使用bash,我建议git-completion.bash
您通过复制到主目录并从您的主目录中获取bash来完成bash完成~/.bashrc
.(我相信我从Pro Git在线书籍中了解到这一点.)在Mac OS X上,我使用以下命令完成了此操作:
# Copy git-completion.bash to home directory
cp usr/local/git/contrib/completion/git-completion.bash ~/
# Add the following lines to ~/.bashrc
if [ -x /usr/local/git/bin/git ]; then
source ~/.git-completion.bash
fi
Run Code Online (Sandbox Code Playgroud)
注意: bash完成不仅适用于标准git命令,还适用于git别名.
最后,为了真正减少击键次数,我将以下内容添加到我的~/.bash_aliases
文件中,该文件来源于~/.bashrc
:
alias gst='git status'
alias gl='git pull'
alias gp='git push'
alias gd='git diff | mate'
alias gau='git add --update'
alias gc='git commit -v'
alias gca='git commit -v -a'
alias gb='git branch'
alias gba='git branch -a'
alias gco='git checkout'
alias gcob='git checkout -b'
alias gcot='git checkout -t'
alias gcotb='git checkout --track -b'
alias glog='git log'
alias glogp='git log --pretty=format:"%h %s" --graph'
Run Code Online (Sandbox Code Playgroud)
wcc*_*526 62
我认为最有用的gitconfig是这样的,我们总是在git中使用20%的函数,你可以试试"g ll",这很神奇,细节如下:
[user]
name = my name
email = me@example.com
[core]
editor = vi
[alias]
aa = add --all
bv = branch -vv
ba = branch -ra
bd = branch -d
ca = commit --amend
cb = checkout -b
cm = commit -a --amend -C HEAD
ci = commit -a -v
co = checkout
di = diff
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
mm = merge --no-ff
st = status --short --branch
tg = tag -a
pu = push --tags
un = reset --hard HEAD
uh = reset --hard HEAD^
[color]
diff = auto
status = auto
branch = auto
[branch]
autosetuprebase = always
Run Code Online (Sandbox Code Playgroud)
Ala*_*avi 16
你需要这个git config alias
命令.在Git存储库中执行以下命令:
git config alias.ci commit
Run Code Online (Sandbox Code Playgroud)
对于全局别名:
git config --global alias.ci commit
Run Code Online (Sandbox Code Playgroud)
Nic*_*ich 10
这对我有用:
bco = "!f(){ git branch ${1} && git checkout ${1}; };f"
Run Code Online (Sandbox Code Playgroud)
上:
$ git --version
git version 1.7.7.5 (Apple Git-26)
Run Code Online (Sandbox Code Playgroud)
对于那些希望在 git alias 中执行 shell 命令的人,例如:
$ git pof
Run Code Online (Sandbox Code Playgroud)
在我的终端中将强制当前分支推送到我的原始存储库:
[alias]
pof = !git push origin -f $(git branch | grep \\* | cut -d ' ' -f2)
Run Code Online (Sandbox Code Playgroud)
哪里
$(git branch | grep \\* | cut -d ' ' -f2)
Run Code Online (Sandbox Code Playgroud)
命令返回当前分支。
所以这是手动输入分支名称的快捷方式:
git push origin -f <current-branch>
Run Code Online (Sandbox Code Playgroud)
Follwing是用于节省时间的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
Run Code Online (Sandbox Code Playgroud)
现在测试一下!
$ 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
Run Code Online (Sandbox Code Playgroud)
您可以为git和non-git命令添加别名.看起来这是在1.5版本中添加的.git config --help
我的Mac上2.5.4版页面上的代码段显示:
如果别名扩展以感叹号为前缀,则将其视为shell命令.
例如,在您的全局.gitconfig
文件中,您可以:
[alias]
st = status
hi = !echo 'hello'
Run Code Online (Sandbox Code Playgroud)
然后运行它们:
$ git hi
hello
$ git st
On branch master
...
Run Code Online (Sandbox Code Playgroud)
如果您使用 '!',您还可以链接命令 操作符产生一个shell:
aa = !git add -A && git status
Run Code Online (Sandbox Code Playgroud)
这将添加所有文件并为您提供带有$ git aa
.
要方便地检查别名,请添加以下别名:
alias = config --get-regexp ^alias\\.
Run Code Online (Sandbox Code Playgroud)
然后快速$ git alias
为您提供您当前的别名以及它们的作用。
对我来说(我在终端上使用 mac)仅在我添加.bash_profile并打开另一个选项卡以加载更改时才有效:
alias gst="git status"
alias gd="git diff"
alias gl="git log"
alias gco="git commit"
alias gck="git checkout"
alias gl="git pull"
alias gpom="git pull origin master"
alias gp="git push"
alias gb="git branch"
Run Code Online (Sandbox Code Playgroud)
小智 6
我在用户目录( vim ~/.profile )的 .profile 中添加了所有别名命令。
alias gs='git status'
alias gp='git pull'
alias gph='git push'
alias gd='git diff | mate'
alias gau='git add --update'
alias gc='git commit -m'
alias gca='git commit -v -a'
alias gb='git branch'
alias gba='git branch -a'
alias gco='git checkout'
alias gcob='git checkout -b'
alias gcot='git checkout -t'
alias gcotb='git checkout --track -b'
alias glog='git log'
alias glogp='git log --pretty=format:"%h %s" --graph'
alias gfo='git fetch origin'
Run Code Online (Sandbox Code Playgroud)
然后,我在 bash 和 zsh shell 中添加了 source 命令。
在 bash shell 中(vim ~/.bashrc)
source ~/.profile
Run Code Online (Sandbox Code Playgroud)
在 zsh shell 中( vim ~/.zshrc )
source ~/.profile
Run Code Online (Sandbox Code Playgroud)
将以下行添加到您的主目录中的 ~/.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-"
Run Code Online (Sandbox Code Playgroud)
完成后,您可以做git a
而不是git add
例如。这同样适用于别名标题下的其他命令。
我创建了dog
用于显示日志图的别名:
git config --global alias.dog "log --all --decorate --oneline --graph"
Run Code Online (Sandbox Code Playgroud)
并按如下方式使用它:
git dog
Run Code Online (Sandbox Code Playgroud)
一条线设置
$ 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'
Run Code Online (Sandbox Code Playgroud)
用法:
$ git st
$ git co
$ git br
$ git ci
$ git last
$ git unstage <file | dir>
Run Code Online (Sandbox Code Playgroud)
一切都将设置为:
$ 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 --
Run Code Online (Sandbox Code Playgroud)
希望这更快。
小智 5
要在 Git 中创建任何别名,请使用以下命令:
git config --local alias.s status
git config --local alias.c commit
Run Code Online (Sandbox Code Playgroud)
git s
On branch master
nothing to commit, working tree clean
Run Code Online (Sandbox Code Playgroud)
git status
On branch master
nothing to commit, working tree clean
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
213197 次 |
最近记录: |