git和python交互_使用Python连接和执行GIT命令

我尝试使用python连接和执行GIT命令,如pull、check status、add和commit新文件等

但我似乎对GIT可执行文件有一个问题。我遵循了教程中的代码来编写T,除非像PyCharm那样为我设置环境。在

我收到以下错误:

提高重要性(err)

ImportError:错误的git可执行文件。

git可执行文件必须以下列方式之一指定:

-包含在您的$PATH中

-通过$GIT_PYTHON_GIT_EXECUTABLE设置

-通过显式设置git.刷新()

在纠正之前,所有git命令都将出错。

通过设置$GIT_PYTHON_REFRESH环境变量,此初始警告在将来可以被静音或加重。

使用以下值之一:

-安静| q |沉默| s |无| n | 0:无警告或例外

-warn | w | warning | 1:对于打印的警告

-错误| e | raise | r | 2:对于引发的异常

示例:

export GIT_PYTHON_REFRESH=安静

我已经将我的环境变量“Path”设置为Git\bin Path,这是另一个用户在这里提出类似问题时通知的,但是没有效果。在

非常感谢任何帮助!在import os

from git import Repo

COMMITS_TO_PRINT = 5

def print_commit(commit):

print('----')

print(str(commit.hexsha))

print("\"{}\" by {} ({})".format(commit.summary,

commit.author.name,

commit.author.email))

print(str(commit.authored_datetime))

print(str("count: {} and size: {}".format(commit.count(),

commit.size)))

def print_repository(repo):

print('Repo description: {}'.format(repo.description))

print('Repo active branch is {}'.format(repo.active_branch))

for remote in repo.remotes:

print('Remote named "{}" with URL "{}"'.format(remote, remote.url))

print('Last commit for repo is {}.'.format(str(repo.head.commit.hexsha)))

if __name__ == "__main__":

repo_path = os.getenv('GIT_REPO_PATH')

# Repo object used to programmatically interact with Git repositories

repo = Repo(repo_path)

# check that the repository loaded correctly

if not repo.bare:

print('Repo at {} successfully loaded.'.format(repo_path))

print_repository(repo)

# create list of commits then print some of them to stdout

commits = list(repo.iter_commits('master'))[:COMMITS_TO_PRINT]

for commit in commits:

print_commit(commit)

pass

else:

print('Could not load repository at {} :('.format(repo_path))

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
YOLO系列是基于深度学习的端到端实时目标检测方法。 PyTorch版的YOLOv5轻量而高性能,更加灵活和易用,当前非常流行。 本课程将手把手地教大家使用labelImg标注和使用YOLOv5训练自己的数据集。课程实战分为两个项目:单目标检测(足球目标检测)和多目标检测(足球和梅西同时检测)。  本课程的YOLOv5使用ultralytics/yolov5,在Windows和Ubuntu系统上分别做项目演示。包括:安装YOLOv5、标注自己的数据集、准备自己的数据集(自动划分训练集和验证集)、修改配置文件、使用wandb训练可视化工具、训练自己的数据集、测试训练出的网络模型和性能统计。 除本课程《YOLOv5实战训练自己的数据集(Windows和Ubuntu演示)》外,本人推出了有关YOLOv5目标检测的系列课程。请持续关注该系列的其它视频课程,包括:《YOLOv5(PyTorch)目标检测:原理与源码解析》课程链接:https://edu.csdn.net/course/detail/31428《YOLOv5目标检测实战:Flask Web部署》课程链接:https://edu.csdn.net/course/detail/31087《YOLOv5(PyTorch)目标检测实战:TensorRT加速部署》课程链接:https://edu.csdn.net/course/detail/32303《YOLOv5目标检测实战:Jetson Nano部署》课程链接:https://edu.csdn.net/course/detail/32451《YOLOv5+DeepSORT多目标跟踪与计数精讲》课程链接:https://edu.csdn.net/course/detail/32669《YOLOv5实战口罩佩戴检测》课程链接:https://edu.csdn.net/course/detail/32744《YOLOv5实战中国交通标志识别》课程链接:https://edu.csdn.net/course/detail/35209 《YOLOv5实战垃圾分类目标检测》课程链接:https://edu.csdn.net/course/detail/35284  

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值