【问题标题】:How can I create a bash or zsh alias for git commit, git pull, git push and pull on a remote server?如何在远程服务器上为 git commit、git pull、git push 和 pull 创建 bash 或 zsh 别名?
【发布时间】:2015-12-26 03:55:20
【问题描述】:

如果我在终端中输入以下内容,我可以完成我想要的一切:

git commit -am "my commit message" ; git pull ; git push ; ssh user@server 'cd /path/to/git/repo/ ; git pull ; exit'

我想在我的~/.zshrc 中创建一个别名。比如:

alias pushit () { git commit -am "$@" ; git pull ; git push ; ssh user@server 'cd /path/to/git/repo/ ; git pull ; exit' }

要像这样在终端中运行:

pushit "my commit message"

相反,每次我重新加载 ~/.zshrc (source ~/.zshrc) 或打开一个新的终端窗口时,我都会看到它循环通过我的别名数十次。目前尚不清楚它是否实际运行。

我做错了什么?

注意事项:

  1. 这不适用于关键任务服务器。它仅供个人使用。我知道这很糟糕。
  2. 我宁愿不使用 git 的 [别名] 工具,这样我就可以将所有别名保存在同一个位置 (~/.zshrc)。

【问题讨论】:

    标签: bash terminal zsh zshrc zsh-alias


    【解决方案1】:

    你想要一个函数而不是别名:

    function pushit () { 
        git commit -am "$@"
        git pull
        git push
        ssh user@server -- 'cd /path/to/git/repo/ ; git pull'
    }
    

    【讨论】:

    • 当我使用这个功能时,我的终端给了我一个fatal: bad revision-Error。这是什么意思?
    • 由于某些原因,它会忽略引号。但我不知道为什么
    猜你喜欢
    • 1970-01-01
    • 2014-03-09
    • 1970-01-01
    • 2017-11-23
    • 2012-06-24
    • 1970-01-01
    • 2012-01-16
    • 2014-10-15
    • 2012-09-07
    相关资源
    最近更新 更多