Most of the time, I imagine it happens whenever we’re working on code and then hopping back and forth between the IDE and a terminal and committing code to make sure we’re not losing any changes.
This happens long enough, and then we end up committing a consumer key and consumer secret or a username and password or something similar to the repository.
Luckily, we can remove commits to revert our code, but most source control systems end up keeping a history of everything (which is a good thing). But what if we need to go about removing Git commit history in both our local and remote repositories?
Removing Git Commit History
For this example, I’m assuming you’re working with Git, and you’re working with the command-line (though I’d imagine most GUIs would allow for the ability to do this).
Next, I’m assuming that the commit you want to remove from your history is the most recent commit and you just want to go back one step.
To go about completely removing git commit history, there are only two things you need to do:
- rebase to the previous commit,
- push the branch to the remote.
To do this, check the middle two steps here:
The additional steps before and after the main commits allow you to get a visual list of commits in case you want to choose a separate commit to which you want to rollback.
And you can run the command both before and after the other two commands (as seen in the gist above) to make sure the list of commits appears how you want in the history of the project.