Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

                                                            sha256
1 010e16069f8858640c2bb9af4a2293b720161b71d9d6e1f375c30237ea2b4123

### Reverting Local Git Commits

You discover an error / something you left out / something new to add straight after the commit.

git reset HEAD~

This is a soft reset. Your changes are preserved. The commit is removed from the record.

### Reverting Commits Pushed to Remote (e.g. Github)

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.

git reset HEAD^ --hard
git push origin -f

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.

git checkout gh-pages
git pull

git push -f origin gh-pages

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.