python - 如何使用远程分支 pull 、推

标签 python git gitpython

我正在尝试自动化一个更改过程,该过程当前创建手动推送到 Git 的源代码。我正在尝试使用 GitPython 包装该代码:

from git import *

# create the local repo
repo = Repo.init("/tmp/test/repo", bare=True)
assert repo.bare == True

# check status of active branch
repo.is_dirty()

# clone the remote repo
remote_repo = repo.clone("http://user:pass@git/repo.git")

# compile source code into repository
# ... 

# track untracked files
repo.untracked_files

# commit changes locally
repo.commit("commit changes")

# push changes to master
remote_repo.push()

当我尝试运行它时,我得到了

Traceback (most recent call last):

File "git_test2.py", line 33, in

repo.commit("commit changes")

BadObject: 636f6d6d6974206368616e676573

该脚本能够 pull 远程存储库,但提交失败。对此有更好的方法吗?

最佳答案

您正在使用的某些功能可能无法按您期望的方式运行。通常,Repo 方法等同于具有相同名称的 git 子命令。

如果您尝试克隆远程存储库,这可以在一行中实现:

repo = Repo.clone_from("http://user:pass@git/repo.git", "/tmp/test/repo")

参见 API Reference有关如何使用 GitPython 的更多信息。

关于python - 如何使用远程分支 pull 、推,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22670765/

相关文章:

python - GitPython:本地和远程删除多个标签

python - 根据多种条件过滤数据框

python - 在 Pandas 中创建时间范围

python - Numpy.where 在字符串数组上使用正则表达式

python - 如何在不下载文章的情况下使用Newspaper3k库?

git - 如何将 git 存储库用作 svn :external?

python - 无法使用 gitpython 创建/添加新分支到 git repo

python-3.x - python : Mocking a local gitpython repository

git - 为将来的 git commit 设置提交消息

git - Visual Studio 2015 : Git Diff Tool Window is empty