How do I delete a commit from my branch history? Should I use git reset –hard HEAD?
Careful: git reset –hard WILL DELETE YOUR WORKING DIRECTORY CHANGES. Please store any local changes you would like to make before running this command. If you are sitting on that commit, this will wack it… and so will — hard HEAD1 — be reset .\n\nThe pre-head commit is the HEAD1. Or, you could look at the output of git log, find the commit id of that commit you want to back up to, then do this: \”git reset –hard sha1-commit-Id>\”.\n\nIf you pushed it, git push origin HEAD –force force push — to remove it.\n\nBut if others have pulled it, then you should start a new branch. When they pull it will just merge it into their work and you will get it back up. If you already pushed, git reverted, to make an \”mirror image\” commit that will reverse the changes. But both commits will be in the log.\n\nIf you want to remove WORK IN PROGRESS.It, which will reset you back to the latest commit, and erase all the changes in your working tree and index, git stash does the same except you can restore it later if you need – versus permanently delete with reset hard mode. Check your stashes by putting \’stashashASH@123\’ using GitHub stash list and .\n\nLastly, if you have to find a commit that you \”deleted\”, it is usually in git reflog unless you\’ve garbage gathered your repository.