如何使此git命令成为别名?

如何使此git命令成为别名?,git,bash,alias,Git,Bash,Alias,我想做一个别名,如下所示 gc这是一条测试消息转换为git commit-m“这是一条测试消息” 我该怎么做?我想在我的bashrc中使用它。bashalias定义不带参数 尝试在.bashrc中使用bash函数: function gc () { git commit -m "$*" } 这不是别名,但请尝试 function gc() { git commit -m "$*" } 我的.bashrc中有以下别名: alias ga='git add' alias gp='

我想做一个别名,如下所示

gc这是一条测试消息
转换为
git commit-m“这是一条测试消息”


我该怎么做?我想在我的bashrc中使用它。

bash
alias
定义不带参数

尝试在.bashrc中使用bash函数:

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

这不是别名,但请尝试

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

我的.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'
我通常使用gm“msg”提交

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

不幸的是,gc已经是一个子命令,不能使用别名。

我喜欢并尝试了这一点,但在我的bash env中不起作用。您知道我为什么会收到此错误消息吗?:错误:路径规范“”与git已知的任何文件都不匹配。。我在这里像$gc test commit消息一样运行它。。我还试着给函数做了一个别名,我猜结果调用在你想要的之前有一个结束引号。您可以尝试添加一行
echo“git commit-m”$*“
在函数中的实际行之前查看生成的内容。感谢您回来。我用回声仪试了一下,然后我发现它起作用了。。我以前肯定错过了什么,但现在它起作用了。仅供参考,有了你的回音,我想你错过了一句话,我不确定它们是否嵌套;所以我是这样做的:
echo“git commit-m\”$*\”
Nice,谢谢分享。我喜欢在当前目录上获取git状态,因为在项目中CWD上方还有其他文件夹我没有工作,所以添加了以下内容:
alias gs='git status'.
。。由于它是我的#1 git cmd,因此速度更快
alias g=gs