我如何使用GitPython来确定是否:
要检查本地和远程是否相同,我这样做:
def local_and_remote_are_at_same_commit(repo, remote):
local_commit = repo.commit()
remote_commit = remote.fetch()[0].commit
return local_commit.hexsha == remote_commit.hexsha
Run Code Online (Sandbox Code Playgroud)
例如
commits_behind = repo.iter_commits('master..origin/master')
和
commits_ahead = repo.iter_commits('origin/master..master')
然后你可以使用类似下面的东西从迭代器到计数:
count = sum(在commits_ahead中为1表示)
这是最后一次使用GitPython 1.0.2检查的.