Undo last commit github

The struggling Developer
3 min readJan 23, 2021

Problem

You are busy developing and committed all code to the your central github repository. But then something happened and you need undo the commit on github.

Solution

You have two options:

  1. Reversing a commit
  2. Removing the commit (reset head)

In this article I´m showing you Option 2: Removing the commit, also called resetting the head.

Resetting the head to undo the last commit on github needs to be executed locally first and then force pushed to the target repository.
You have two options to reset:

  1. Soft
  2. Hard

Resetting hard means undoing the last commit and loosing the code.
Resetting soft means that the last commit is undone and the code changes are applied to the source code in the directory.

In my experience you want to use the soft option.

The process to undo your last commit on github looks like this:

  1. Enter the directory where the source code is
  2. Execute “git reset — hard HEAD~” to use the hard option or “git reset — soft HEAD~”.
  3. Execute “git push — force $branch” to push your changes to your github repository.

Result:
You did undo the last commit on github

--

--