0

Let's say I have an open Pull Request on Github and I pushed a new commit to the branch/PR.
Now I want to just ignore/undo the last commit only.

this is the git log output:

commit xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Author: John Doe <John Doe@gmail.com>
Date:   Wed Oct 19 22:55:39 2022 -0700

    last commit

commit yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
Author: John Doe <John Doe@gmail.com>
Date:   Mon Sep 26 14:38:21 2022 -0700

    some tweks

commit zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Author: John Doe <John Doe@gmail.com>
Date:   Mon Sep 26 11:51:19 2022 -0700

    bla bla

I already pushed the last commit to remote / open PR.

What is the best way to "cancel" ONLY the last commit and leave things exactly how it was before the commit xxxxxxxxxxxxxxxxx?

Is there a better/cleaner way than:

execute locally git reset HEAD^1 to undo the last commit then push it?

PlayHardGoPro
  • 2,791
  • 10
  • 51
  • 90
  • 2
    The answer is, as long as you are on your own branch that only you push things into, is to reset locally back to the previous commit, then do a force push. This will **not** be appropriate if you are on a shared branch that others will push to. – Lasse V. Karlsen Oct 20 '22 at 12:58

1 Answers1

0

You can use git reset commitId to undo the last commit Else you can use git reset --soft HEAD~1 to uncommit the changes Or you can use git reset --hard HEAD~1 to completely delete the changes