Vannkorn

Full Stack Web Developer

Close

Remove 1 commit from a remote branch

I know this is stupid, but sometimes shit happens.

Ads: Register now via this link to receive $300 credit from Vultr

As a developer the situation when you accidentally commit unwanted codes or credentials or codes that should not be there happens quite often, especially when you’re the project lead.

This can be implemented easily if your source code is managed by Git.

The steps to achieve this are:

  1. Reset back to your desired commits. In this example, I’ve moved back 1 commit
    git reset --hard HEAD~1
  2. Push your changes to match the remote repository.
    git push --force

That’s it!

Leave a Reply

Your email address will not be published. Required fields are marked *