Python的高级Git库 Gittle
作者:mdxy-dxy 发布时间:2023-06-14 14:52:05
Gittle是一个高级纯python git 库。构建在dulwich之上,提供了大部分的低层机制。
Install it
pip install gittle
Examples :
Clone a repository
from gittle import Gittle repo_path = '/tmp/gittle_bare'repo_url = 'git://github.com/FriendCode/gittle.git' repo = Gittle.clone(repo_url, repo_path)
With authentication (see Authentication section for more information) :
auth = GittleAuth(pkey=key)Gittle.clone(repo_url, repo_path, auth=auth)
Or clone bare repository (no working directory) :
repo = Gittle.clone(repo_url, repo_path, bare=True)
Init repository from a path
repo = Gittle.init(path)
Get repository information
# Get list of objectsrepo.commits # Get list of branchesrepo.branches # Get list of modified files (in current working directory)repo.modified_files # Get diff between latest commitsrepo.diff('HEAD', 'HEAD~1')
Commit
# Stage single filerepo.stage('file.txt') # Stage multiple filesrepo.stage(['other1.txt', 'other2.txt']) # Do the commitrepo.commit(name="Samy Pesse", email="samy@friendco.de", message="This is a commit")
Pull
repo = Gittle(repo_path, origin_uri=repo_url) # Authentication with RSA private keykey_file = open('/Users/Me/keys/rsa/private_rsa')repo.auth(pkey=key_file) # Do pullrepo.pull()
Push
repo = Gittle(repo_path, origin_uri=repo_url) # Authentication with RSA private keykey_file = open('/Users/Me/keys/rsa/private_rsa')repo.auth(pkey=key_file) # Do pushrepo.push()
Authentication for remote operations
# With a keykey_file = open('/Users/Me/keys/rsa/private_rsa')repo.auth(pkey=key_file) # With username and passwordrepo.auth(username="your_name", password="your_password")
Branch
# Create branch off masterrepo.create_branch('dev', 'master') # Checkout the branchrepo.switch_branch('dev') # Create an empty branch (like 'git checkout --orphan')repo.create_orphan_branch('NewBranchName') # Print a list of branchesprint(repo.branches) # Remove a branchrepo.remove_branch('dev') # Print a list of branchesprint(repo.branches)
Get file version
versions = repo.get_file_versions('gittle/gittle.py')print("Found %d versions out of a total of %d commits" % (len(versions), repo.commit_count()))
Get list of modified files (in current working directory)
repo.modified_files
Count number of commits
repo.commit_count
Get information for commits
List commits :
# Get 20 first commits repo.commit_info(start=0, end=20)
With a given commit :
commit = "a2105a0d528bf770021de874baf72ce36f6c3ccc"
Diff with another commit :
old_commit = repo.get_previous_commit(commit, n=1)print repo.diff(commit, old_commit)
Explore commit files using :
commit = "a2105a0d528bf770021de874baf72ce36f6c3ccc" # Files treeprint repo.commit_tree(commit) # List files in a subpathprint repo.commit_ls(commit, "testdir") # Read a fileprint repo.commit_file(commit, "testdir/test.txt")
Create a GIT server
from gittle import GitServer # Read onlyGitServer('/', 'localhost').serve_forever() # Read/WriteGitServer('/', 'localhost', perm='rw').serve_forever()
猜你喜欢
- 有时候,因为内容的更改或者隐私问题,我们往往不 希望别人通过“百度快照”的方法 查看 自己网站的某一些网页,对于网站管理员来说,百度快照也分
- ps:不曾想还有那么好用的方法。汗一个先。Div即父容器不根据内容自适应高度,我们看下面的代码:<div id="main&
- scipyscipy包包含致力于科学计算中常见问题的各个工具箱。它的不同子模块相应于不同的应用。像插值,积分,优化,图像处理,,特殊函数等等
- 对python3下的requests使用并不是很熟练,今天稍微用了下,请求几次下来后发现出现连接超时的异常,上网查了下,找到了一个还算中肯的
- 图像加法1.使用Numpy加法运算方式:结果=图像1+图像2原理:图像数据格式为unit88位二进制表示范围是0到255。二进制相加1.不超
- ndarray.ndim:维度ndarray.shape:形状ndarray.size:元素个数ndarray.dtype:元素数据类型nd
- 在Pydev能正常执行的脚本,在导出后在命令行执行,通常会报自己写的包导入时找不到。一:报错原因在PyDev中,test.py 中导入Tes
- 1、Numpy ndarray对象numpy ndarray对象是一个n维数组对象,ndarray只能存储一系列相同元素。#一维数组[1,2
- 前言中位数是一个可将数值集合划分为相等的上下两部分的一个数值。如果列表数据的个数是奇数,则列表中间那个数据就是列表数据的中位数;如果列表数据
- lambda/filter/map/reduce这几个函数面试中很肯定会用到,本篇主要介绍这几个函数的用法。1 lambda匿名函数,用法如
- Pandas Shift函数基础在使用Pandas的过程中,有时会遇到shift函数,今天就一起来彻底学习下。先来看看帮助文档是怎么说的:&
- DEMO:var testobj = document.getElementById("test&q
- 之前在比赛的时候需要用Python实现灰色关联分析,从网上搜了下只有实现两个列之间的,于是我把它改写成了直接想Pandas中的计算工具直接计
- 将Django与其他现有认证系统的用户名和密码或者认证方法进行整合是可以办到的。例如,你所在的公司也许已经安装了LDAP,并且为每一个员工都
- PHP现在推出5.3.0版本了,不过下载的时候有几个不同版本选择。那就是VC6 X86和VC9 X86。首先我来解答:VC6是什么?VC6就
- 只能是一些限定的东西运行代码框ENTER键可以让光标移到下一个输入框 <input onkeydown="if(event.
- php中可以使用 mb_detect_encoding() 函数来判断字符串是什么编码的。当在php中使用mb_detect_encodin
- #!/usr/bin/env python##-*- coding: utf-8 -*- import os print
- 阅读Chapter 1 清单Chapter 2 标题总览:不但所有网页都需要有标题,而且如果标记正确的话,他们能为网页设计和易用性
- 注意:index.html再次声明变量的时候注意空格的问题来源:https://blog.csdn.net/guofeng93/articl