【问题标题】:How do I make this shorter in my terminal?如何在我的终端中缩短它?
【发布时间】:2015-11-16 06:15:00
【问题描述】:

git add .; git commit -m 'MESSAGE'; git push origin master

要记住的事情很长...有没有办法可以做到,所以我只需要输入例如gitcommit -'MESSAGE' ?我尝试使用alias,但我不知道如何执行-'MESSAGE' 部分...

附:我在 osx 上,如果相关的话

【问题讨论】:

    标签: git github terminal


    【解决方案1】:

    在您的终端上安装 zshell,您将获得 ga 等命令的非常短的别名。对于 git 添加。和 gca -m "message" 用于 git commit 和 ggpush 和 ggpull 用于 git push 和 git pull。这里是安装教程http://sourabhbajaj.com/mac-setup/iTerm/zsh.html

    【讨论】:

    • 不过,@choroba 的 gitcommit "message" 更短;)
    • 是的,如果您只想将代码推送到 master 或任何特定分支,它会更短。我是 Rails 程序员,我发现 zshell 很有帮助:)
    【解决方案2】:

    别名不处理参数,但函数处理:

    gitcommit () {
        # set -e
        git add .
        git commit -m "$1"
        git push origin master
    }
    

    我可能会在函数中添加set -e,因为如果添加不成功,您不希望 git 提交。

    您可以将函数定义添加到您的 .bashrc.bashprofile 文件中,以便每次启动 shell 时都可以使用它。

    【讨论】:

    • 好的,那我把函数放到终端里了,怎么调用呢? gitcommit("MESSAGE") ?
    • 我在哪里set -e
    • 为方便起见,您始终可以创建一个别名来调用相关函数(或脚本)。
    【解决方案3】:

    当您在 linux 上时,请编写一个 bash 函数。在一行中完成所有这些。

    function gcommit {
        git add .
        git commit -m "$1"
        git push origin master
    }
    

    把它放在你的~/.bash_profile 然后你可以使用如下命令:

    #gcommit "Your message"
    

    【讨论】:

      猜你喜欢
      • 2012-12-22
      • 2015-08-08
      • 1970-01-01
      • 2020-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多