2012-08-08 17 views

risposta

6

ho cercato reset in the documentation e trovato this:

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

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

Ripristina la nostra testa alla data impegnarsi opzionalmente sincronizzare l'indice e albero di lavoro. Anche il riferimento a cui facciamo riferimento verrà impostato per il commit.

10

È possibile utilizzare:

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

Oppure, se avete bisogno di ripristinare un ramo specifico:

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

o nel mio caso, se si desidera aggiornare solo difficile un repo a origine/master (avviso, questo cambierà le modifiche correnti):

# 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 Puoi usare:

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