2016-02-24 46 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' –