I accidently pushed something that I shouldn't have and now I want to revert it, but I can't because if I do reset hard to 05669, it doesn't let me to push it because the remote HEAD is ahead...
I read on other questions that doing a forced push will cause trouble for others, but that's also what they recommend (huh?), should I really do a force push to fix this? is there another way that won't cause trouble for others?
If the remote branch is used by other team members, especially if it's the main development branch, then git reset
is dangerous because it removes a commit that other people have already pulled. Also you need to do a git push --force
which means you need to have the permission to do so.
The safest option is to revert the commit using the git revert command.
This will keep your existing commits, and then will add an extra revert commit on top. This is safe because you're not changing history, or removing commits already pulled and relied on by other team members. Note that if things get out of hand during reverting (e.g., you get a conflict that you're not sure how to resolve) you can always abort the operation by git revert --abort
.