Anu*_*har 11 python git gitpython
那么标题是自我解释的.相当于git reset --hard使用GitPython模块运行(在终端上)的python代码是什么?
ble*_*ted 16
您可以使用:
repo = git.Repo('c:/SomeRepo')
repo.git.reset('--hard')
Run Code Online (Sandbox Code Playgroud)
或者,如果您需要重置为特定分支:
repo.git.reset('--hard','origin/master')
Run Code Online (Sandbox Code Playgroud)
或者在我的情况下,如果你想简单地将回购更新为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()
Run Code Online (Sandbox Code Playgroud)
您可以使用:
repo = git.Repo('repo')
# ...
# Remove last commit
repo.head.reset('HEAD~1', index=True, working_tree=True)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5215 次 |
| 最近记录: |