Git reset 1 commit / revert last commit

2 points
Asked by:

How can I reset 1 commit back with Git?

I don't want to keep anything eg any local files not commited etc, I just want to roll back 1 commit.

Nothing else, nothing more.

Thanks for the answer.

1 answers
2 points
Answered by:

Quick solution:

git reset --hard HEAD~1

Practical example:

Take a look at this screenshot, flow:

  1. git log show us 2 commits
  2. We execute:
    git reset --hard HEAD~1
  3. git log show us 1 commit, because we removed 1 commit

People somethimes call git reset:

  • rollback 1 commit
  • revert 1 commit
  • remove 1 commit from git history
  • undo last commit


0 comments Add comment
Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.