目录 前言 导入库 声明git指令和路径 解析git分支名 调用subprocess 总结 前言 在git开发时,编译/编译后的文件是依赖于当前的git分支名的,读取其名字,可便于后续的操作。 导入库 import subprocess 声明git指令和路径 cmd_command = "git branch --show-current" GitBash_path = r'D:\Bitbucket\Test' GitBash_path 是正常输入git指令的所在路径。 解析git分支名 def parse_branchname(branchname: str): temp