Rewinding a remote branch [GIT]
![Rewinding a remote branch [GIT]](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1595846859885%2FQXz3zux6i.png&w=3840&q=75)
Developer and Builder 🔨⚒️⚙️
You were working in a feature branch but accidentally pushed commits to the master/develop branch, it happens.
First, you have to know the exact commit ID or number of commits that was pushed. You can use git log pretty=oneline to get the information.
If you don't have an exact copy of the branch you would love to revert and would love to keep the commit history, then create a dummy branch that will hold the exact commit logs, ensure it branches from the branch with the original changes git checkout -b {dummy-branch-name}
Next, return back to the branch you pushed to accidentally with git checkout {branch-name} and run git reset {commit-id} --hard if you have a valid commit ID or git reset HEAD^{commit-count} if you have a commit count you want to revert back to.
The about command would rewind all the changes.
Next, do git stash to put the changes aside in a trash can, ensure that the head of the current branch is at the exact commit you want, then run git push --force. This would force a rewrite in the remote branch and revert the changes as you had done locally.
I hope this takes someone from a distress!!!
Gracias


