【问题标题】:One GIT command to rule them all (gacp: git-add-commit-push)一个 GIT 命令来统治它们(gacp:git-add-commit-push)
【发布时间】:2012-11-23 12:04:16
【问题描述】:

我真的很喜欢一个专门的 git 别名/bash 函数,它可以执行以下操作。

git add -A
git commit -m "$MESSAGE"
git push origin master

只需一条命令即可。

gacp
> My message
CONTENTS OF COMMIT
CONTENTS OF PUSH

这可以吗?有人可以分享一些示例代码吗?有没有原生的 git 函数可以做到这一点?

【问题讨论】:

    标签: git bash terminal command alias


    【解决方案1】:

    参考答案:git add, commit and push commands in one?

    你可以试试gitu

    第一次(必须安装node js):

    npm install -g git-upload
    

    之后:

    gitu COMMIT_MSG
    

    同时发出这三个命令。

    好处是您在重新安装系统或想在不同的计算机上执行此操作时不必担心,并且不需要修改文件。 这也适用于不同的平台(不仅是 Linux 和 Mac,还包括 Windows),只是您必须安装 npmnodejs(当然是 git)。

    【讨论】:

      【解决方案2】:

      在我的 Windows 机器上。我设置了这个 bashrc 别名,让整个过程更简单。

      • 创建/定位您的 .bashrc - refer stack overflow thread

      • 将以下行添加到文件中

        alias gacp='echo "enter commit message :" && read MSG && git add . && git commit -m "$MSG" && git push'

      • 重新加载 .bashrc / 关闭并重新打开你的 shell

      • 现在您可以使用 gacp 命令完成整个过程。

      【讨论】:

        【解决方案3】:

        如果你在 linux 上,只需编写一个 shell 脚本或创建一个别名

        例如。

        #!/usr/bin/sh
        
        set -x  # Output executed commands
        set -e  # Make script fail as soon as one command fails
        
        read MESSAGE
        
        git add -A
        git commit -m "$MESSAGE"
        git push origin master
        

        【讨论】:

        • 另外,将其命名为git-foo,将其放在$PATH 中的某个位置,然后您可以使用git-foogit foo 运行它。
        • 如何,在 linux/unix 中你可以制作一个“控制台”类型的界面。我讨厌为第一个参数添加引号,如果在我键入命令后有一个带有某种标识符的新行,例如>,那么这将是消息/参数。
        【解决方案4】:

        前两个命令可以用 :

        启动
        git commit -a -m "$MESSAGE"
        

        然后,您可以查看其他命令:

        git pull --rebase 
        git rebase -i
        

        之前做一个 git push。

        【讨论】:

          猜你喜欢
          • 2013-11-04
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-08-07
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多