Skip to content

Removing a Commit From a GitHub Repository

Murdo Moyse edited this page Jan 9, 2020 · 2 revisions

Remove a Commit

Editing the git history is bad practice in version control and should only be done in the case of a security issue.

Furthermore, please make sure that the author of the commit removes the file from their version of the branch, otherwise the same issue will occur.


1.Type the following command into GitBash/Command prompt (optional: you can include the hash value of the commit if you want to reset a specific commit).

git resetsoft HEAD^

This will reset the repository to a previous state.

2.Use the following git command to show that the repository has been returned to a previous state.

git commit -mReverting to the state of the project at <commit/commit hash>

Edit <commit/commit hash> to state the specific commit/commit hash you are reverting to

3.Type the following git command into GitBash/Command prompt.

git push origin <name_of_branch> --force

4.Check the GitHub page here, finding the relevant repository/branch, to ensure the commit was removed from the commit history.

5.Ensure the author of the commit also follows this step-by-step guide to remove/modify the commit in their clone of the repository.