Hi for ilustration purposes this is the tree at the server.
(...) Change to E from user TTT Change to D from user LLL Change to C from user me Change to B from user QQQ Change to A from user TTT (...)
I accidentally pushed C, how can I remove it from the main repository without affecting all the work my colleages pushed afterwards?
And if possible still keeping it as a local commit for myself.
The command you want is
git revert. It creates a commit to cancel out another commit:You can then push that to the main repository, and the change made by the commit will be reverted, while still leaving the commit itself (and subsequent history) intact:
To continue working based on it yourself, you can then revert the revert, or cherry-pick the original commit – hopefully on a local branch so you won’t accidentally push it!