AdyAdy
AdyAdy

Reputation: 1038

Remove some content of a file from git history

When the repository was set up, in the initial commit one of the added files contained sensitive data (a programmers personal info) that should not have been there. Is it possible to completely erase that from the git history? Not the whole file, only a few lines with the sensitive data.

The repository is fairly new so there are no branches and that specific file was not modified since the initial commit. (PS: I'm fairly new to git, I don't yet understand complex commands)

Upvotes: 3

Views: 2160

Answers (2)

John Zwinck
John Zwinck

Reputation: 249582

You can edit the file now to remove the offending content in a new commit, then interactively rebase that commit. A step-by-step guide is here: https://stackoverflow.com/a/21353994/4323 but the gist is:

make sure you have a backup
edit thefile
git commit thefile -m "remove details"
git rebase -i --root

Now you will see a list of commits. Change the last one ("remove details") from "pick" to "fixup", and move it to be after the first commit.

You'll probably need to git push -f after this, to rewrite history at your origin server.

Upvotes: 8

sp1nakr
sp1nakr

Reputation: 388

This one you could have searched for first. See e.g. this post http://help.github.com/removing-sensitive-data/ or http://help.github.com/removing-sensitive-data/

Upvotes: -2

Related Questions