自动提交存储库中的更改

时间:2016-02-24 08:12:38

标签: python gitpython

我们正在尝试自动提交遗留目录的更改,人们不希望使用类似版本控制(叹息)的内容。

我正在使用gitpython每晚提交这些更改:

repo = git.Repo(local_directory)

changed_files = [change.a_blob.path for change in repo.index.diff(None)]
if changed_files or repo.untracked_files:

   if changed_files:
      repo.git.add(update=True)

   if repo.untracked_files:
      repo.git.add(repo.untracked_files)

   repo.git.commit(message='Auto committed')
   repo.remotes.origin.push(repo.head)

有时提交失败,“'git commit --message = Auto committed'返回退出代码1” - 我无法重现

我做错了吗?我读过,也许我应该使用repo.index进行提交?

最佳, 克里斯托弗

1 个答案:

答案 0 :(得分:1)

你是绝对正确的,你需要使用repo.index进行提交。这是我的脚本中使用GitPython的一个工作示例(顺便帮助我们进行版本控制)

repo = Repo(repo_dir)
index = repo.index

然后我的commit_version函数:

def commit_version(requested_version, commit_msg, index, version_file):
    """Commits version to index"""

    print "Committing: ", requested_version

    index.add([version_file])
    index.commit(commit_msg)

因此,您可以将“自动提交”作为commit_msg传入。希望这有帮助!

相关问题