如何将 "git push" 别名为自身 + 运行 脚本?
How to alias "git push" into itself + running a script?
我需要 运行 一个脚本,在我推送后通知我的 CI 服务器。因此我需要将“git push”别名为“git push; powershell script.ps1”。这是我正在尝试的:
$ alias git push='git push; powershell script.ps1'
bash: alias: git: not found
或者,表示空白字符 returns 这个:
$ alias git\ push='git push; powershell script.ps1'
bash: alias: `git push': invalid alias name
$ alias "git push"='git push; powershell script.ps1'
bash: alias: `git push': invalid alias name
如何在每次推送时将我的脚本别名为 运行?
这有效:
git config --global alias.push "push; powershell ./script.ps1"
命令 运行s,但是使用“git push”仍然没有 运行 我的脚本。
是的,我知道我可以为此使用 webhook,但 CI 服务器必须保持完全本地化。是的,我知道我可以为此使用 NGROK,但我的公司不允许。
Git 不允许别名覆盖正确的命令名称。为您的别名使用其他标签。
并且如果别名内容混合了 git 命令和 shell 命令,您必须在前面加上 !
来告诉 git 传递命令shell 解释。
尝试
git config --global alias.p '!git push; powershell ./script.ps1'
# then to invoke it, just
git p
另一个小改进是使用 &&
而不是 ;
来链接您的命令,以防推送失败。然后它将停止执行不必要的后续操作。
git config --global alias.p '!git push && powershell ./script.ps1'
我需要 运行 一个脚本,在我推送后通知我的 CI 服务器。因此我需要将“git push”别名为“git push; powershell script.ps1”。这是我正在尝试的:
$ alias git push='git push; powershell script.ps1'
bash: alias: git: not found
或者,表示空白字符 returns 这个:
$ alias git\ push='git push; powershell script.ps1'
bash: alias: `git push': invalid alias name
$ alias "git push"='git push; powershell script.ps1'
bash: alias: `git push': invalid alias name
如何在每次推送时将我的脚本别名为 运行?
这有效:
git config --global alias.push "push; powershell ./script.ps1"
命令 运行s,但是使用“git push”仍然没有 运行 我的脚本。
是的,我知道我可以为此使用 webhook,但 CI 服务器必须保持完全本地化。是的,我知道我可以为此使用 NGROK,但我的公司不允许。
Git 不允许别名覆盖正确的命令名称。为您的别名使用其他标签。
并且如果别名内容混合了 git 命令和 shell 命令,您必须在前面加上 !
来告诉 git 传递命令shell 解释。
尝试
git config --global alias.p '!git push; powershell ./script.ps1'
# then to invoke it, just
git p
另一个小改进是使用 &&
而不是 ;
来链接您的命令,以防推送失败。然后它将停止执行不必要的后续操作。
git config --global alias.p '!git push && powershell ./script.ps1'