1

I tried and also google it but never solve this problem. I found this command git reset --hard HEAD^ it also doesn't work.

  • If you have pushed to the repo, it's generally a bad habit to remove the commit. However if you didn't push the commit you can do the reset trick by specifying origin/head. Beware it will revert to the last pushed commit – cnaimi Jan 04 '22 at 15:18
  • Does this answer your question? [Remove last commit from remote git repository](https://stackoverflow.com/questions/8225125/remove-last-commit-from-remote-git-repository) – Sasha Jan 04 '22 at 15:20
  • I will suggest you do the modifications to override your previous commit – Pawan.Java May 11 '22 at 07:05
  • Does this answer your question? [How do I undo the most recent local commits in Git?](https://stackoverflow.com/questions/927358/how-do-i-undo-the-most-recent-local-commits-in-git) – Jeremy Caney May 17 '22 at 00:17

2 Answers2

1

The git reset --hard HEAD^ instruction does not remove a commit by definition. It just forces the branch to point to the previous (parent) commit (^) on your local repository. To have the same status on the remote repository, you need to force push using git push <remote (default: origin)> <target_branch> --force. Be aware this push can erase others' works. You can use --force-with-lease instead of --force for more secure use.

0

Please use this command git reset --soft HEAD~1

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 11 '22 at 23:57