How to undo the last push done on Github?

Asked

Viewed 7,465 times

5

I’m trying to learn Git and in the middle of my tests I made a push incorrect for Github.

I did the reset of the latter commit and tried to give a push again thinking that it would remove the commit on Github, but it was a mistake:

     ! [rejected]        master -> master (non-fast-forward)
    error: failed to push some refs to '[email protected]:Ferreira-Jefferson/StarWarsRepo.git'
    hint: Updates were rejected because the tip of your current branch is behind
    hint: its remote counterpart. Integrate the remote changes (e.g.
    hint: 'git pull ...') before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.

How I correctly undo the last push made for Github? And how have I ever made one reset, what I must do now?

  • Did you pull before trying the new Push? First from a "git pull" and then try "git push" again

1 answer

8


How are you trying to rewrite the repository history, which is not a good practice, when doing the push it is necessary to use the flag -f:

git push -f

But the ideal would be for you to make another commit reversing what is wrong, but keeping the history. What can be done as follows:

  • Do the pull changes that are in the remote repository with git pull.
  • Then create a commit reversing the changes. If only the last commit, can use git revert HEAD^.
  • After that do the push usually without the flag -f.
  • But the ideal would be for you to do another commit by reversing what is wrong, but keeping the history ...truth, because this is the purpose of Git Thank you for the Reply!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.