Home > other >  Undo a git pull to be in sync with recovered remote master
Undo a git pull to be in sync with recovered remote master

Time:01-28

I pushed something from my local branch to remote master. This was a mistake and the admin will remove that push in the remote repo. In the mean time (by yet another mistake) I also pulled this change from remote master to local master. Now I want to obliterate this pull from my local repo, so that once remote repo goes to a previous state my repo will still be in sync with it.

Is it enough to right-click on previous revision in log dialog and select "reset 'master' to this..." (which does a git reset to a previous revision), and then revert all changes in working directory, or do I have to something else or something more?

Additional question. Is hard reset the same аs mixed reset followed up by a revert?

CodePudding user response:

You have the right idea. To make sure everything is in sync, however, I would wait for the admin to remove your push, do a git fetch so that you have the latest origin/master, and then do a git reset hard origin/master while on your master branch. This will point your local master branch to the same commit origin/master points to. Note that if there are other developers who have pulled master since your accidental push, they will need to do the same.

As to your additional question: a revert creates a new commit, whereas a reset moves the current branch to point to a new commit, so a hard reset is not equivalent to a mixed reset plus a revert. It is equivalent to a mixed reset plus discarding changes in the working directory (e.g. by doing a git checkout .). Perhaps that is what you meant by "revert," but just want to be clear that an actual git revert is a different concept.

  •  Tags:  
  • Related