2012-08-08 52 views

回答

6

我搜索resetthe documentation發現this

class git.refs.head.HEAD(repo, path='HEAD')

reset(commit='HEAD', index=True, working_tree=False, paths=None, **kwargs)

重置我們的頭上給定犯可選同步指標和工作樹。我們所引用的參考將被設置爲提交。

10

您可以使用:

repo = git.Repo('c:/SomeRepo') 
repo.git.reset('--hard') 

或者,如果您需要重置到一個特定的分支:

repo.git.reset('--hard','origin/master') 

或者對於我來說,如果你想只是很難更新回購協議原產地/主人(警告,這會導致你當前的變化):

# blast any current changes 
repo.git.reset('--hard') 
# ensure master is checked out 
repo.heads.master.checkout() 
# blast any changes there (only if it wasn't checked out) 
repo.git.reset('--hard') 
# remove any extra non-tracked files (.pyc, etc) 
repo.git.clean('-xdf') 
# pull in the changes from from the remote 
repo.remotes.origin.pull() 
1

Y您可以使用:

repo = git.Repo('repo') 
# ... 
# Remove last commit 
repo.head.reset('HEAD~1', index=True, working_tree=True)