首页 > 解决方案 > 打开一个新的 git-bash 终端并在其中运行命令

问题描述

我设置了一个预提交挂钩来在 git 中运行单元测试。这意味着每次我运行 git commit 命令时,它都会自动运行 pytest。

但是,这会使我的 git-bash 终端停止一段时间。我想要一个命令来打开一个新的 git-bash 窗口并在其中自动运行 git commit -m $mycomment 。

我知道我可以通过输入 git-bash 来运行新的 git-bash(因为 git-bash.exe 在我的路径中),但是如何在它之后运行 'git commit $mycomment'?谢谢

标签: bashgitgit-bash

解决方案


您可以将命令放在 bash shell 脚本中。我们称之为:<脚本名称>。

chmod +x <script name>
git-bash -c <script name>

我会在脚本中添加一个 sleep 命令,以便您查看任何结果。


推荐阅读