问题
I want to create a bat script that do the following :
opens git bash
run commands on git bash (ex.
git init
,git add .
, ...)
Context: I am working on an idea, that I will access git-bash through java.
I use Netbeans IDE
回答1:
You don't have to open git bash at all to execute a sequence of git commands in a script:
Create your bash script as any other script:
#!/bin/bash
git ...
#other commands
Save it as git-myscript
(no extension) anywhere referenced by your $PATH
or %PATH%
(this works even on Windows)
Run it with git myscript
: it will be executed by the git bash.
This work for any file named git-xxx
: you can call that file as a bash script with git xxx
.
(on Linux, Mac or Windows)
来源:https://stackoverflow.com/questions/41660025/how-to-script-git-commands-in-a-windows-bat-script