'How can I remove last commit from git repository

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



Solution 1:[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.

Solution 2:[2]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Houssem Ben Ali
Solution 2 Alex Akash