python的简单git包装器
python-git-wrapper的Python项目详细描述
Git包装
简单的pythongit包装器
这个库是一个简单的git包装器,允许您以一种强大而简单的方式对任何git存储库执行许多操作。在
要求
这个库已经过python>;=3.7、3.8测试,您需要安装Git>;2.22.0
入门
这个库非常简单,你只需要指出你的存储库在哪里或者创建一个新的。在
from python_git_wrapper import Repository
repository = Repository('.') # Path of your git repository. It could be relative to your project or absolute
或者如果存储库还不存在
^{pr2}$添加文件:
repository.add_files('path to any file')
提交更改:
repository.commit('commit message')
最后,推动他们:
repository.push()
组件
该库分为3个主要组件。在
Git Service:包含与Git进程正确通信的所有数据的对象。在
- 注意:如果您没有在路径中配置git二进制文件的路径。执行下一个命令:
GitService.singleton('git path'')
- 注意:如果您没有在路径中配置git二进制文件的路径。执行下一个命令:
Repository:它将是您的入口点,您将与之交互以提供检索所有信息的功能。它是对要处理的存储库的引用。在
在Git元素:
Commit:包含任何提交的所有相关信息
在Branch:包含分支的名称
在Status:在工作目录中构建所有更改的对象
在
API概述
关于此库功能的小概述。所有这些方法和属性都可以被repository对象访问。在
Method | Description | Return |
---|---|---|
build | Create or init a new git repository | Repository |
commit | Commit the staged changes | Status |
status | Retrieve the Status of the Working Directory | Status |
push | Push Changes to remote repository | Status |
pull | Pull changes to remote repository | Status |
checkout | Change HEAD reference | Status |
create_branch | Create a new branch, go there if necessary | Branch |
merge_branches | Merge two branches. Support different merge modes | Branch |
add_remote | Add a new remote repository | Status |
remove_remote | Remove a remote repository | Status |
execute | execute any git command in the repository | str |
revert_last_commit | Generate a new commit reverting the previous one | Commit |
change_last_commit_message | Rewrite the previous commit message | Commit |
get_commit_by_position | Retrieve Commit by position in the current branch | Commit |
get_branches_by_commit | Retrieve all the branches which contain one specific commit | Commit |
详细的API规范Here。在
- 项目
标签: