Location>code7788 >text

git rolls back a previous commit

Popularity:111 ℃/2024-09-10 10:08:31

git version rollbacks, for commits or rollbacks by mistake

I. Rollback to a previous version and none of the commits after that version (for version rollback)

1), first check the version number, use the git log command to view the version to be rolled back corresponding to the commit Id

commit 17829e208cd170928fd0f3adb3f3bde1b1eabb76

2), rollback to a previous version (after the execution of the local has been rolled back, the remote repository has not been rolled back)

git reset --hard version number

3)、Rollback remote warehouse

git push -f

 

II. Rollback to a previous version, but post-release commits still need to be retained

1), check the version number to be rolled back

git log

2) Rollback to previous version

git revert -n version number

3), submit

git commit "Remarks information"

4)、Push to remote warehouse

git push

 

Commit but don't push to the remote repository (git commit but don't push), undo the changes to the workspace

git reset --soft HEAD^ 

Note: The code remains after the commit has been revoked.