Search code examples
githubcommitgit-commit

How to delete specific commit histories in Github created via file upload?


I normally upload my files to Github repository through the web interface. I accidentally uploaded a file to Github repository recently and this file contains information which I don't want others to see. Now, this private info is permanently recorded in the commit history.

How can I delete this specific commit from Github?

EDIT: The commit history was created through the file upload website of github. It was not created using git.


Solution

  • I will answer my own question. Credit goes to sasha-dev for his comment.

    Here is what I did.

    • Use Github desktop to clone the github repostitory.
    • Launch command-line prompt. Go to the repository folder. Run the following command;

    git reset --hard HEAD~1 # remove last commit

    Or the goal is to remove a specific commit, find out the commit hash

    git reset --hard <commit hash>~
    

    Next step is to force push the locally made changes to the remote github repository. Run this command;

    git push -f
    

    Commits will be removed from github repository at this point.