How do you reset a Git repository to a certain commit? This example will delete the commits made after the commit you want to reset to, and then we’ll push it to origin.
This is what my latest commit looks like on a testrepo, but lets say I want the signs?
commit to be the latest commit.
Git reset
Make sure you are on the branch where the commit is. I’m doing this on master.
Then use git reset –hard <commit-hash> to set the current branch HEAD to the commit you want.
When we push the change to origin when need to use force
This is how the commits looks on my testrepo origin now:
Background and source
A colleague asked me how to set the HEAD of a branch to an older commit. I thought of using revert. But that would save the changes in a revert-commit, which was not desired this time. So I didn’t know how. My colleague found a stack overflow thread containing the answer that we tried and was successful with.