如何在git中使用python和dulwich获取标签列表并创建新标签? [英] How to get a list of tags and create new tags with python and dulwich in git?

查看:92
本文介绍了如何在git中使用python和dulwich获取标签列表并创建新标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用python检索git repo的以下信息时遇到问题:

I am having problems to retrieve the following information of a git repo using python:

  1. 我想获取此存储库的所有标签的列表.
  2. 我想签出另一个分支,并创建一个新的分支进行登台.
  3. 我想用带注释的标签来标记提交.

我研究了dulwich的文档,其工作方式似乎很简单.还有其他更容易使用的替代方法吗?

I have looked into the dulwich's documentation and the way it works seems very bare-bones. Are there also alternatives which are easier to use?

推荐答案

使用Dulwich获取所有标签的最简单方法是:

The simplest way to get all tags using Dulwich is:

from dulwich.repo import Repo
r = Repo("/path/to/repo")
tags = r.refs.as_dict("refs/tags")

标签现在是一个字典,用于映射用于提交SHA1的标签.

tags is now a dictionary mapping tags to commit SHA1s.

签出另一个分支:

r.refs.set_symbolic_ref("HEAD", "refs/heads/foo")
r.reset_index()

创建分支:

r.refs["refs/heads/foo"] = head_sha1_of_new_branch

这篇关于如何在git中使用python和dulwich获取标签列表并创建新标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆