2016-02-24 34 views
3

我们正试图自动提交遗留目录上的更改,其中人们不想使用类似版本控制(叹气)的内容。自动提交存储库中的更改

我使用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的承诺--message =自动致力于’退出码1返回” - 我不能重现

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

最好,克里斯托弗

回答

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。希望这可以帮助!

+0

感谢您的评论!所以用repo.remotes.origin.push(repo.head)推动仍然是一样的? – Schinken

+1

是的,'repo.remotes.origin.push'是正确的......虽然你可能能够逃避不包括'repo.head' –