python操作git
2024-08-27 12:27:40
GitPython 是一个用于操作 Git 版本库的 python 包,它提供了一系列的对象模型(库 - Repo
、树 - Tree
、提交 - Commit
等),用于操作版本库中的相应对象。
模块安装
pip install gitpython
初始化
from git import Repo
repo =Repo("D:\s17\c.py") #git文件的路径
操作
from git import Repo
repo =Repo("F:\git") #git文件的路径 #获取当前所在的分支 git branch
print(repo.active_branch) #添加到缓存区 git add命令
repo.index.add(["test.txt"]) #提交到版本库 git commit -m
repo.index.commit("创建test文件") #添加版本号 git tag -a
repo.create_tag("v0.1") #创建分支 git branch dev
repo.create_head("dev") #回退到某个版本 git reset --hard hash
repo.index.reset(commit="哈希地址",head=True) #获取所有分支
print([str(b) for b in repo.branches]) #查看标签
print(repo.tags)
import git
#git clone
clone = git.Repo.clone_from("url","to_path") #git pull
clone.remote().pull() #git push
clone.remote().push()
gitpython还可以直接操作git命令
g = git.Git("PATH")
g.add()
g.commit("-m ")
最新文章
- js 使某个页面不允许在子iframe中打开的解决办法
- Java学习-014-文本文件写入实例源代码(两种写入方式)
- (转)javascript中event对象详解
- Android自定义长按事件
- 用css做类似表格的布局
- Css3渐变实例Demo(一)
- U盘装系统系列二—-如何设置U盘启动
- [Swust OJ 838]--最优价值(0-1背包+数学)
- AsyncTask简单入门
- MySQL 常用基础命令
- oracle系列--解锁数据库
- 解决ubuntu不能安装g++的问题
- 【tomcat8】consider increasing the maximum size of the cache
- Number()和new Number()的区别以及一种简单实现
- jQuery 文档操作之prepend() 和prependTo()方法.
- react_app 项目开发 (3)_单页面设计_react-router4
- Add custom field in Material Master
- Eloquent JavaScript #11# The Document Object Model
- vuex深入理解 modules
- mysql排序数据
热门文章
- 小程序bindtap和cachetap的区别
- [转]在static代码块或static变量的初始化过程中使用ServiceManager提供的api的陷阱
- Vue-计算属性和侦听属性
- shiroUtil工具类
- [Kubernetes]浅谈容器网络
- 前端笔记知识点整合之JavaScript(三)关于条件判断语句、循环语句那点事
- ubuntu server 16.04 安装过程中提示无法安装busybox-initramfs
- Python——字符串2.0(实验)
- vue computed、methods、watch的区别
- MYSQL 单表一对多查询,将多条记录合并成一条记录