模块安装
pip install gitpython
基本用法
1. 初始化
from git import Repo
Repo.init('/data/test2') # 创建一个git文件夹
2. 添加与提交
repo.index.add(['a.txt']) #将文件提交到缓存区
repo.inex.commit('update new') # 将缓存区文件提交到版本库
3. 回滚
repo.index.checkout(['a.txt']) # 回滚缓存区文件
repo.index.reset(commit='486a9565e07ad291756159dd015eab6acda47e25',head=True) #回滚版本库文件
4.分支
repo.create_head('debug') # 创建分支
5. tag
repo.create_tag('v1.0') # 创建tag