如何将多个命令传递给 Git BASH
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35044574/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to Pass Multiple Commands to Git BASH
提问by dudeNumber4
New to Git. Running it on windows. When I run this command in a .sh file (from a BASH shell), it works:
Git 新手。在 Windows 上运行它。当我在 .sh 文件(来自 BASH shell)中运行此命令时,它可以工作:
cd /c/SomeDir && git commit -a -m "commit comment"
cd /c/SomeDir && git commit -a -m "提交评论"
I want to do that with a variable comment, so I want to call: C:\Program Files\Git\usr\bin\bash.exe and pass the above command (2 commands chained) as the parameter (with a different comment each time).
我想用一个变量注释来做到这一点,所以我想调用: C:\Program Files\Git\usr\bin\bash.exe 并将上述命令(链接的 2 个命令)作为参数(每个都有不同的注释)时间)。
It doesn't work; looking for ideas...
它不起作用;寻找想法...
Clarification:I'm using a utility to run commands, but basically, this is all I want to call:
Executable:
C:\Program Files\Git\usr\bin\bash.exe
Parameters (if test.sh has everything it needs but the comment):
bash /c/somewhere/test.sh "my comment"
澄清:我正在使用一个实用程序来运行命令,但基本上,这就是我想要调用的全部:
Executable:
C:\Program Files\Git\usr\bin\bash.exe
参数(如果 test.sh 拥有它需要的一切但评论):
bash /c/somewhere/test.sh“我的评论”
Alternatively, the Parameters could simply be:
cd /c/MyRepoDir && git commit -a -m "my comment"
或者,参数可以简单地为:
cd /c/MyRepoDir && git commit -a -m "my comment"
Further:Even after creating a .sh script, calling bash, and running that script, I still get an error, "Paths with -a does not make sense." Then, even after doing what's recommended here(same commands), I STILL get the same error.
进一步:即使在创建 .sh 脚本、调用 bash 并运行该脚本之后,我仍然收到错误消息,“带有 -a 的路径没有意义。” 然后,即使在执行此处推荐的操作(相同的命令)之后,我仍然会遇到相同的错误。
回答by Calvin Taylor
try putting $1 in to reference the first parameter
尝试将 $1 放入引用第一个参数
cd /c/SomeDir && git commit -a -m ""
so myScript.sh contains your line, then
所以 myScript.sh 包含你的行,然后
bash myScript.sh "this is my commit message"
an alternative to this approach from using cd is pushd and popd
使用 cd 的这种方法的替代方法是 pushd 和 popd
#!/bin/bash
pushd mygitdir
git commit -a -m ""
popd