Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git delete pushed commit and remove history entry

Tags:

git

commit

I have pushed some changes to the repository.

I want to delete the last commit from the repository and permanently remove the history entry as well.

How can I do this?

like image 223
n00b.exe Avatar asked Nov 14 '17 11:11

n00b.exe


Video Answer


1 Answers

Try:

git checkout <branch> // replace branch with a name of the branch you worked on
git reset --hard HEAD~1 // this command removes the latest commit
git push --force-with-lease origin <branch> // push the changes to the remote

If nobody modified the remote while doing the operation above your push will be accepted, otherwise it may be rejected. Further steps are dependant on if you can use -f instead of --force-with-lease. If so do it, but it will overwrite other's changes. If not - it can't be done without changing the history.

like image 112
Opal Avatar answered Sep 25 '22 13:09

Opal