It is possible that you make a commit without verifying the changes you are committing and don’t notice your error in time. Once you review the commit and notice that there is something in the commit that doesn’t belong there, how do you remove that specific commit?
To easily remove all the changes from a local
git
repository, usegit reset --hard HEAD~
In this short post I will explain how to delete a commit in your repository and push the changes remotely.
From your git
repository, first, find the commit you want to remove by looking at git log
:
|
|
Depending on position of your commit, modify the below command (below command will show the last 4 commits).
|
|
This will put you in the editor. You will see something similar to:
|
|
Delete the line that corresponds to the commit you want to delete and save the file. Check that the changes were applied correctly.
|
|
To push this change to a remote repository, do the following (don’t forget the +
):
|
|