I have to revert to an earlier commit after my stuff has been already pushed and deployed.
I have used git checkout HEAD^
to check it out, but how to push it now? it says branch is uptodate!
Any help is greatly appreciated!”””
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You have two options. You can revert the erroneous commit with
git revert HEAD. This will generate a new commit which undoes the previous commit. You can then push that as with any other commit.If you want the history to show the commit never existed, you can remove the commit with
git reset --hard HEAD^. (Note that this will discard any changes you made to the working directory. You can then push with the-fflag to force the commit to be removed from the remote repository. Note when doing this that others may run into problems if they have fetched the commit you remove. More importantly, if anyone has pushed anything since your commit, those commits will be lost. If you’re not sure if anyone else has accessed the repo, the first options is safest.EDIT
As Jefromi mentions, you will want to check out the branch you were working on before doing either of the above or you will cause additional problems.