我看过一个视频,在那里有人已经得到了
git st
git ci
如何使用Git?我尝试着去做,但是却遇到了一个错误提示,问我是否指的是别的什么东西。
作为一个Git新手,我需要知道完成这个任务需要做些什么?
我看过一个视频,在那里有人已经得到了
git st
git ci
如何使用Git?我尝试着去做,但是却遇到了一个错误提示,问我是否指的是别的什么东西。
作为一个Git新手,我需要知道完成这个任务需要做些什么?
基本上,您只需要向~/.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命令甚至可以接受函数作为参数。请查看别名。
git config --global
将别名放置在~/.gitconfig
中,而不是.git/config
(当前存储库的配置文件)。 - Cascabelst
命令来查看状态,而不是使用 status -s
(简短状态)命令。 - hasen'
,像这样:git config --global alias.sr 'svn rebase'
。 - Amir Raminfar"
而不是单引号,例如:git config --global alias.ci "commit -v"
。 - ABVincita正如其他人所说,添加git别名的适当方法是在全局的.gitconfig
文件中进行,可以通过编辑~/.gitconfig
文件或使用git config --global alias.<alias> <git命令>
命令来实现。
以下是我~/.gitconfig
文件中别名部分的副本:
[alias]
st = status
ci = commit
co = checkout
br = branch
unstage = reset HEAD --
last = log -1 HEAD
git-completion.bash
复制到你的主目录中,并在~/.bashrc
中引用它,以设置bash自动补全功能。(我相信我是从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
注意: 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'
~/.bashrc
文件“获取”的意思? - ahnbizcad~/.bashrc
:真正减少按键次数的好方法。正是我一直在寻找的。 - parasrish我认为最有用的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
你需要使用git config alias
命令。在Git仓库中执行以下命令:
git config alias.ci commit
对于全局别名:
git config --global alias.ci commit
如果您使用'!'运算符生成一个shell,您也可以链接多个命令:
aa = !git add -A && git status
这将同时添加所有文件并通过$ git aa
提供状态报告。
为了方便地检查您的别名,请添加此别名:
alias = config --get-regexp ^alias\\.
然后,快速运行$ git alias
可以获取当前的别名及其作用。
这对我有效:
bco = "!f(){ git branch ${1} && git checkout ${1}; };f"
在:
$ git --version
git version 1.7.7.5 (Apple Git-26)
!
开头的Git别名命令,请注意:“自Git 1.5.0版本起,Git支持通过在值前加上“!”来执行非Git命令的别名。”(参考文献:https://git.wiki.kernel.org/index.php/Aliases#Advanced) - Sam我为展示日志图表创建了别名dog
:
git config --global alias.dog "log --all --decorate --oneline --graph"
使用方式如下:
git dog
以下是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
对于我来说(我使用带终端的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"
[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
。同样的方法也适用于其他在别名标题下的命令。