2012-08-08 9 views

Respuesta

6

Busqué reset en the documentation y encontró this:

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

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

Restablecer la cabeza a lo dado cometer sincronizar opcionalmente el índice y el árbol de trabajo. La referencia a la que nos referimos se establecerá para que se comprometa también.

10

Se puede utilizar:

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

O si es necesario restablecer a una rama específica:

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

O en mi caso, si desea actualizar sólo difícil un acuerdo de recompra a origen/maestro (advertencia, esto nukeará sus cambios actuales):

# 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 Puede usar:

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