2014-03-12 29 views

回答

0
tagref = TagReference.list_items(repo)[0] 
print tagref.commit.message 

來自docs

0

因爲這些限制,我放棄了GitPython。令人討厭的不是很喜歡。這個簡單的類需要照顧所有的東西混帳的(除了初始化一個新的回購,並權威性的):

class PyGit: 
    def __init__(self, repo_directory): 
     self.repo_directory = repo_directory 
     git_check = subprocess.check_output(['git', 'rev-parse', '--git-dir'], 
              cwd=self.repo_directory).split("\n")[0] 
     if git_check != '.git': 
      raise Exception("Invalid git repo directory: '{}'.\n" 
          "repo_directory must be a root repo directory " 
          "of git project.".format(self.repo_directory)) 

    def __call__(self, *args, **kwargs): 
     return self._git(args[0]) 

    def _git(self, *args): 
     arguments = ["git"] + [arg for arg in args] 
     return subprocess.check_output(arguments, cwd=self.repo_directory).split("\n") 

所以現在你可以做任何你可以在git的事:因爲

>>> git = PyGit("/path/to/repo/") 

>>> git("checkout", "master") 
["Switched to branch 'master'", 
"Your branch is up-to-date with 'origin/master'."] 

>>> git("checkout", "develop") 
["Switched to branch 'develop'", 
"Your branch is up-to-date with 'origin/develop'."] 

>>> git("describe", "--tags") 
["1.4.0-rev23"] 

>>> git("tag", "--contains", "ex4m9le*c00m1t*h4Sh") 
["1.4.0-rev23", "MY-SECOND-TAG-rev1"] 
+0

加入GitHub上我剛開始使用這個很多。 https://github.com/mijdavis2/PyGit – mjd2