简体   繁体   中英

Undo a git push on the remote branch without changing local repository?

A developer in my team committed his changes to the wrong remote repository. I want to remove what he pushed to this repository on the remote repository. I don't want to change anything locally.

Therefore how can I:

  1. List the commits on the remote repository branch so that I can see which commits that have been pushed need to be removed.

  2. Remove each of these commits on the remote repository branch so that I can go back to the commit before he pushed his changes.

I am not sure if "removing" is the correct process or if it is meant to be "revert" but in the end I need the remote repository branch to be back to where it was before he pushed his changes.

Mark where that branch was last by

git tag original-master origin/master

inspect what you get from the server:

git fetch

git log --all --graph

or

gitk --all

if your tag still makes sense that that's where the remote branch should be, force push that up:

git push -f origin original-master:master

if it's another commit, push that commit as the master:

git push -f origin <some SHA1>:master

clean up:

git tag -d original-master

update your tracking branches since the fix:

git fetch

This assumes "master" is the branch in question. Replace "master" with the proper branch name if it's another one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM