Imaging that we commit and push the wrong code and we want to reset completely. So we can use git reset
with --hard
and then push back to the remote repository with git push
Case study
We want to reset commit add deployed on IIS to the previous commit Update sdk + lib + packages
Step 1: Copy the SHA of the commit before the wrong commit. This case, the wrong commit is add deployed on IIS and we will reset the branch to the previous commit Update sdk + lib + packages with SHA 1027e32f9393b568e2e11e5bbf062f598fe7ba1b
.
git reset 1027e32f9393b568e2e11e5bbf062f598fe7ba1b --hard
Step 2: Push back to the remote repository:
git push origin -f
Now, the lastest commit will be Update sdk + lib + packages
Next post will show how to recover a reset/deleted commit, read here: https://nready.net/recover-a-reset-or-deleted-commit-in-git-with-git-reflog/
—
Personal experiment
Nam Le.
Last modified on May 26th, 2022 at 3:24 pm
Nam Le
lequocnam
0 responds