Git remove last commits from remote made by someone else
Asked Answered
M

1

3

So, my situation is (by mistake) I have given access to a person to commit to my branch. Now in my local I have made a commit and when I tried to push it to the remote it shows that the remote is ahead. Because the other person has pushed his code to this branch with several commits. Now, can I remove those commits from remote without taking pull to my local?

I tried to do this git push origin +<<commit number>>^:branch

But it says src refspec <<commit number>>^ does not match any.

Moraceous answered 10/5, 2016 at 8:4 Comment(3)
Why don't you git push -f origin <<branch>> . The -f will destroy the origin tree and replace it by your local one. If you do not want to force push, as fat as i know, you can't rebuilt the tree without pulling the modificationsExosphere
Ok so I can do this without taking pull right?Moraceous
Yes, this is a regular push (it just rewrite the commit tree)Exosphere
D
5

Please try this

git push origin <<branch_name>> -f

In this -f if used for force push

This will remove commits that are made by someone else.

Decrepitude answered 10/5, 2016 at 8:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.