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 ")

最新文章

  1. js 使某个页面不允许在子iframe中打开的解决办法
  2. Java学习-014-文本文件写入实例源代码(两种写入方式)
  3. (转)javascript中event对象详解
  4. Android自定义长按事件
  5. 用css做类似表格的布局
  6. Css3渐变实例Demo(一)
  7. U盘装系统系列二—-如何设置U盘启动
  8. [Swust OJ 838]--最优价值(0-1背包+数学)
  9. AsyncTask简单入门
  10. MySQL 常用基础命令
  11. oracle系列--解锁数据库
  12. 解决ubuntu不能安装g++的问题
  13. 【tomcat8】consider increasing the maximum size of the cache
  14. Number()和new Number()的区别以及一种简单实现
  15. jQuery 文档操作之prepend() 和prependTo()方法.
  16. react_app 项目开发 (3)_单页面设计_react-router4
  17. Add custom field in Material Master
  18. Eloquent JavaScript #11# The Document Object Model
  19. vuex深入理解 modules
  20. mysql排序数据

热门文章

  1. 小程序bindtap和cachetap的区别
  2. [转]在static代码块或static变量的初始化过程中使用ServiceManager提供的api的陷阱
  3. Vue-计算属性和侦听属性
  4. shiroUtil工具类
  5. [Kubernetes]浅谈容器网络
  6. 前端笔记知识点整合之JavaScript(三)关于条件判断语句、循环语句那点事
  7. ubuntu server 16.04 安装过程中提示无法安装busybox-initramfs
  8. Python——字符串2.0(实验)
  9. vue computed、methods、watch的区别
  10. MYSQL 单表一对多查询,将多条记录合并成一条记录