简体   繁体   English

如何制作这个git命令别名?

[英]How can I make this git command alias?

I want to make a alias, like this below 我想创建一个别名,如下所示

gc this is a test message convert to git commit -m "this is a test message" . gc this is a test message转换为git commit -m "this is a test message"

How can I do this? 我怎样才能做到这一点? I want that in my bashrc. 我希望在我的bashrc中。

bash alias definitions don't take parameters. bash alias定义不带参数。

Try using a bash function in your .bashrc: 尝试在.bashrc中使用bash函数:

function gc () { 
    git commit -m "$*" 
}

I have these alias in my .bashrc: 我的.bashrc中有这些别名:

alias ga='git add'
alias gp='git push'
alias gl='git log'
alias gs='git status'
alias gd='git diff'
alias gdc='git diff --cached'
alias gm='git commit -m'
alias gma='git commit -am'
alias gb='git branch'
alias gc='git checkout'
alias gra='git remote add'
alias grr='git remote rm'
alias gpu='git pull'
alias gcl='git clone'

I normally commit with gm "msg" 我通常用gm "msg"提交

This isn't an alias, but try 这不是别名,但请尝试

function gc() {
  git commit -m "$*"
}

This should work: 这应该工作:

alias ci = "!f() { git commit -m \"$*\"; }; f"

Unfortunately gc is already a subcommand and can't be aliased. 不幸的是,gc已经是一个子命令,不能别名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM