Introduction to Git and GitHub

Session - Commit to main (and undo last commit!)

Zoë Turner

Accidental commits!

If you commit by accident to any branch, but particularly main, you can undo the last commit

In fact, you can undo any number of last commits!

This has to be done in the Terminal though ($)!

git reset --soft HEAD~1

Resetting doesn’t delete

Be careful if you are trying to undo something sensitive, a reset is not a deletion

Moving changes from one branch to another

What if you’ve made a few changes that you want to keep but committed to main?

  • In RStudio create a new branch (which will have all the changes)
  • Return to main
  • Use the terminal to reset the commits you don’t want

End session