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 answer
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
Native Advertising
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂