2

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)

AdyAdy
  • 988
  • 6
  • 19
  • A filter-branch ought to do it: https://stackoverflow.com/a/4114121/6309 – VonC Aug 05 '17 at 06:41
  • 1
    Possible duplicate of [How to remove/delete a large file from commit history in Git repository?](https://stackoverflow.com/questions/2100907/how-to-remove-delete-a-large-file-from-commit-history-in-git-repository) – ephemient Aug 05 '17 at 06:48

2 Answers2

6

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.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436
  • Thank you! This did the trick. It's gone now from the "initial commit", I hope git doesn't store it as a backup or something anywhere else – AdyAdy Aug 05 '17 at 07:25
  • 1
    @AdyAdy: The original "bad" commit will still exist on disk for a while, until Git decides to clean it. You can make it do that now by following the instructions here: https://stackoverflow.com/questions/1904860/how-to-remove-unreferenced-blobs-from-my-git-repo - note you would need to do this on every clone of the repo if you're paranoid. – John Zwinck Aug 05 '17 at 07:43
-2

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/

sp1nakr
  • 378
  • 2
  • 12
  • 1
    I searched that first, they talk about removing the entire file. I need the file to be there, I only want a few lines from it to be removed. – AdyAdy Aug 05 '17 at 06:48