Procedure to roll back both local and remote changes
You have made a commit.
You discover a mistake or something you left out straight after the commit.
~ git reset HEAD
This is a soft reset. Your changes are preserved. The commit is removed from the record.
Make the additional changes you need. Add files. Commit.
Copy your folder to a backup location.
The following is a hard reset, which rolls back to the previous commit. Changes since that commit will be lost. Force push it to the remote.
^ --hard
git reset HEAD-f git push origin
Both local and remote should now be in sync at the previous commit. You may check with:
git status
If you have Github Actions that are triggered by commits, they will be triggered again despite this being a roll-back. So go and stop those runs if necessary.
Next, if you have another branch such as ‘gh-pages’ that builds automatically on each commit, roll back that branch as well so it keeps in sync. As this branch has been building on the remote, do a git pull to ensure that your local copy is up to date first before resetting.
-pages
git checkout gh
git pull
^ --hard
git reset HEAD-f origin gh-pages git push
Check status. Switch back to ‘main’ branch (substitute whatever branch you were on).
git status git checkout main
Copy back the files with changes you made previously from your backup location.
Make the additional changes you need. Add files. Commit.
For attribution, please cite this work as
shikokuchuo (2021, Aug. 12). shikokuchuo{net}: Reverting Git Commits. Retrieved from https://shikokuchuo.net/posts/13-reverting/
BibTeX citation
@misc{shikokuchuo2021reverting, author = {shikokuchuo, }, title = {shikokuchuo{net}: Reverting Git Commits}, url = {https://shikokuchuo.net/posts/13-reverting/}, year = {2021} }