Windows bat批处理启动调用git-bash.exe 执行shell命令自动提交git push
前言全局说明
Windows bat批处理调用git bash 自动提交git push
一、说明
环境:
Windows 11 家庭版 23H2 22631.3737
二、打开 git bash here 方式
2.1 当前CMD终端窗口打开 git bash here
@echo off "C:\Program Files\Git\bin\bash.exe" --cd=D:\temp
2.2 CMD 窗口打开 git bash here 新窗口
(和手动右键点git bash here 一样)
@echo off "C:\Program Files\Git\git-bash.exe" --cd=D:\temp
注意:系统和git版本不同,bash.exe 或 git-bash.exe 名字不一样,请到安装目录详细查看。
三、bat 批处理,在 git bash here 绝对路径执行命令
@echo off "C:\Program Files\Git\git-bash.exe" --cd=D:\temp -c "pwd; ls -l && read r"
--cd= 指定启动目录,默认路径:命令执行的当前文件夹
-c "pwd; ls -l && read r" 要执行的命令,多个命令用双引号括起来,并用 && 或 ; 分割 (用Linux语法)
read r 相当于pause 暂停,可以让我们有机会看到更新了什么。不加,命令结束,窗口就会自动关闭
四、bat 批处理,在 git bash here 绝对路径执行 sh 脚本
@echo off "C:\Program Files\Git\git-bash.exe" --cd=D:\testt -c "bash git_pull.sh"
其他命令上面解释过,不敷述
"bash git_pull.sh" 执行脚本,脚本内容就是 正常的 shell 脚本
文件名:git_pull.sh
命令运行结果:
(因为没有什么更新,所以没有获取到东西)
五、相对路径
bat 批处理,在 git bash here 相对路径执行命令
@echo off d: "C:\Program Files\Git\git-bash.exe" --cd=testt -c "bash git_pull.sh"
d: 切换到分区 (也可以用:cd /d d:)
testt 就是相对路径,
免责声明:本号所涉及内容仅供安全研究与教学使用,如出现其他风险,后果自负。
参考、来源:
https://blog.csdn.net/onlyAngel521/article/details/121268315
https://geek-docs.com/git/git-questions/1689_git_how_to_launch_git_bash_from_windows_command_line.html
https://geek-docs.com/git/git-questions/246_git_enabling_git_in_windows_10_command_line.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)