我正在尝试自动化一个更改过程,目前会生成需要手动推送到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
该脚本可以拉取远程仓库,但提交时失败。是否有更好的方法解决这个问题?