user3663882 user3663882 - 8 months ago 29
Git Question

Is it possible to revert back to some commit without reset --hard?

I'm pretty new to git and came from mercurial. I did something wrong and pushed it, but some teammates could already pulled these wrong changes. So

reset --hard; push -f
is not an option. Is it possible to tell git that I want to commit changes so that it became is it was 2 commits ago? I mean something like this:


commit 4 <<--- Remote/local master's head
commit 3
commit 2 <<-- I want to git to craft changes so that commit 5
^ is the same as commit 2
commit 1

I want to git to produce changes so that
commit 5
changes files so that they become the same as they were at
commit 2

Is it possible to do?


You can revert the commit using git revert :

git revert commit3 commit4

This will create "reverse" commit, that will unmake the change you've make in the other commits.

The history will still be fast forward, on your way to push it without -f.