Bene, il titolo è auto esplicativo. Quale sarà il codice Python equivalente all'esecuzione di git reset --hard
(sul terminale) utilizzando il modulo GitPython?Come ripristinare un git --hard usando gitPython?
7
A
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
- 1. Come ripristinare un repository git danneggiato?
- 2. git push fallito dopo 'git ripristinare HEAD --hard ~ 1' di repo locale
- 3. Git e hard link
- 4. Come ripristinare il commit git iniziale?
- 5. Git ripristinare il comportamento
- 6. Come git resettare tutto, ma --hard 4 file
- 7. Come posso recuperare un repository remoto con GitPython?
- 8. Come posso resettare --hard HEAD su Mercurial?
- 9. "git checkout tag-name" vs "git reset --hard nome-tag"
- 10. Che differenza c'è tra "git checkout -f" e "git reset --hard HEAD"?
- 11. Differenza tra git reset --hard e git checkout
- 12. Chiavi GitPython e SSH?
- 13. Come ripristinare un "git reset HEAD ~ 1" non necessario
- 14. Come ripristinare un file in Git che è stato rinominato
- 15. Come posso tornare indietro dopo git reset --hard
- 16. Elenco file modificato dall'ultimo commit con GitPython
- 17. errore quando si cerca di ripristinare git TESTA
- 18. Come ripristinare un file nella versione precedente usando TortoiseSVN?
- 19. Git: reset --hard ora sono bloccato in passato
- 20. come ripristinare file cancellati
- 21. Come ripristinare un ramo su github?
- 22. Perché a volte vedo un "nome file" non aggiornato. Impossibile unire. " dopo un 'git reset --hard' e un 'git pull'?
- 23. Come ripristinare un puntatore del sottomodulo Git al commit memorizzato nel repository contenente?
- 24. Come disinstallare un repository git usando pip?
- 25. Come inserisco un commit usando git?
- 26. Come eliminare un ramo remoto usando Git?
- 27. Qual è il significato di git reset --hard origin/master?
- 28. reset git --hard HEAD lascia file non tracciati dietro
- 29. Come ripristinare il repository remoto remoto su git
- 30. Come annullare/ripristinare un UIGestureRecognizer