Recently I had a coworker persist sensitive information in some files managed by version control in a branch that had not made its way into master yet. He was out for the day so I was tasked with modifying the Git history so that the sensitive information would not be visible when doing a $ git log.

What I had to do was the following:
  1. Open up Git BASH
  2. Change the active directory to the repo
  3. Run the following command:
    Code:
    $ git log --oneline
  4. Find the commit hash of the commit where the sensitive information was added to the Git history.
  5. Copy the commit hash of the commit just prior.
  6. Rebase the branch by calling:
    Code:
    $ git rebase -i {hash}
  7. From the interactive mode (using VIM):
    1. Press i to enter edit mode
    2. Replace Pick on the commit I needed to change with Edit
    3. Press esc to exit edit mode
    4. Press Shift + Z + Z to save the changes
  8. With the branch is in rebase mode, I edited the file with the sensitive information and removed it
  9. Staged the changes by running the following command:
    Code:
    $ git add .
  10. Amended the commit with the same commit message by running the following command:
    Code:
    $ git commit --amend -C HEAD
  11. Finished the rebase by running the following command:
    Code:
    $ git rebase --continue


I was nervous about doing this on my actual branch, so for a test run I cloned a backup:
Code:
$ git clone {project name} ./{backup name}